aml-org / amf

AMF (AML Modeling Framework) is an open-source library capable of parsing and validating AML metadata documents.
https://a.ml/docs
Other
3 stars 0 forks source link

RAML1.0 -> OAS3.0: Traits are not resolved #645

Closed Kaiser1989 closed 4 years ago

Kaiser1989 commented 4 years ago

Raml Traits are not resolved, leading to "x-amf-is" and "x-amf-traits".

Converting this simple RAML file:

#%RAML 1.0

title: Trait example
version: v1
baseUri: http://localhost:8080

traits:
  X400:
    responses:
      400:
        description: Bad Request
        body:
          application/json:
            type: string

/meta:
  description: Meta information about this service
  get:
    description: Get app information
    is:
    - X400
    responses:
      200:
        description: OK
        body:
          application/json:
            type: string

Java function to convert raml file to oas file:

public static void ramlToOasWithoutFix(final File raml, final File oas) throws Exception {
    AMF.init().get();
    BaseUnit model = new Raml10Parser().parseStringAsync(new String(Files.readAllBytes(raml.toPath()))).get();
    Files.write(oas.toPath(), new Oas30Renderer().generateString(model).get().getBytes());
}

Output is:

{
  "openapi": "3.0.0",
  "info": {
    "title": "Trait example",
    "version": "v1"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/meta": {
      "description": "Meta information about this service",
      "get": {
        "description": "Get app information",
        "x-amf-is": [
          "X400"
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "x-amf-traits": {
      "X400": {
        "responses": {
          "400": {
            "description": "Bad Request",
            "body": {
              "application/json": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  }
}

The output should be:

`{
  "openapi": "3.0.0",
  "info": {
    "title": "Trait example",
    "version": "v1"
  },
  "servers": [
    {
      "url": "http://localhost:8080"
    }
  ],
  "paths": {
    "/meta": {
      "description": "Meta information about this service",
      "get": {
        "description": "Get app information",
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json":  {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}
tomsfernandez commented 4 years ago

Duplicate of https://github.com/aml-org/amf/issues/646

ShauniArima commented 2 years ago

This issue does not seems to be a duplicate of #646. Resource types seems to be resolved but not traits.

Would you want a sample that expose this behaviour ?

tomsfernandez commented 2 years ago

HI @ShauniArima this issue is a duplicate because the cause (misuse of AMF to migrate between RAML 1.0 and OAS 3.0) is the same. That is why it is a duplicate.

ShauniArima commented 2 years ago

Hmmm I'll check that tomorrow but after resolving the model there is still a bad output. I'll create an example to explain this issue if you want.