raml-org / webapi-parser

API Spec parser based on AMF. Currently supports RAML 0.8, RAML 1.0, OAS 2.0 and OAS 3.0(beta).
Other
68 stars 24 forks source link

When converting RAML -> OAS2, inheritance information is lost #74

Open skingreek opened 4 years ago

skingreek commented 4 years ago

I try convert my RAML to OAS2 for use it for viewing in ReDoc project. Result file not contains valid information about inherent relationship: User is Person and Employee is Person

I use simple code:

    final WebApiBaseUnit result = Raml10.parse("file://../api-specs/raml/discrTest.raml").get();
    Oas20.generateYamlFile(result, "file://oas2_out.yaml").get();

discrTest.raml contains:

#%RAML 1.0
title: My API With Types
types:
  Person:
    type: object
    discriminator: kind # refers to the `kind` property of object `Person`
    properties:
      kind: string # contains name of the kind of a `Person` instance
      name: string
  Employee: # kind can equal `Employee`; default value for `discriminatorValue`
    type: Person
    properties:
      employeeId: integer
  User: # kind can equal `User`; default value for `discriminatorValue`
    type: Person
    properties:
      userId: integer

/resource:
  get:
    responses:
      200:
        body:
          application/json:
            type: Person

As result oas2_out.yaml contains:

swagger: "2.0"
info:
  title: My API With Types
  version: "1.0"
paths:
  /resource:
    get:
      responses:
        "200":
          description: ""
          x-amf-mediaType: application/json
          schema:
            type: object
            x-amf-merge:
              -
                $ref: "#/definitions/Person"
definitions:
  Person:
    type: object
    discriminator: kind
    required:
      - kind
      - name
    properties:
      kind:
        type: string
      name:
        type: string
  Employee:
    type: object
    required:
      - employeeId
    properties:
      employeeId:
        type: integer
    x-amf-merge:
      -
        $ref: "#/definitions/Person"
  User:
    type: object
    required:
      - userId
    properties:
      userId:
        type: integer
    x-amf-merge:
      -
        $ref: "#/definitions/Person"

But i expect like this:

swagger: '2.0'
info:
  title: My API With Types
  version: ''
definitions:
  Person:
    discriminator: kind
    type: object
    properties:
      kind:
        type: string
      name:
        type: string
    required:
      - kind
      - name
  Employee:
    allOf:
      - $ref: '#/definitions/Person'
      - properties:
          employeeId:
            type: integer
        required:
          - employeeId
        type: object
  User:
    allOf:
      - $ref: '#/definitions/Person'
      - properties:
          userId:
            type: integer
        required:
          - userId
        type: object
paths:
  /resource:
    get:
      operationId: GET_resource
      produces:
        - application/json
      responses:
        '200':
          description: ''
          schema:
            $ref: '#/definitions/Person'
postatum commented 4 years ago

Hi @skingreek.

Sorry for the inconvenience. The issue you face come from a dependency lib we use. I've reported it to that lib team.

If it helps, you can "resolve" your RAML document and then generate OAS.

Docs on resolution: https://raml-org.github.io/webapi-parser/resolving.html Example here.