Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

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

Open
skingreek opened this issue Mar 12, 2020 · 1 comment
Open

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

skingreek opened this issue Mar 12, 2020 · 1 comment
Labels
amf Related to AMF issue, bug or specific behavior question Further information is requested

Comments

@skingreek
Copy link

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
Copy link
Contributor

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.

@postatum postatum added the amf Related to AMF issue, bug or specific behavior label Mar 13, 2020
@postatum postatum added bug Something isn't working question Further information is requested and removed bug Something isn't working labels Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
amf Related to AMF issue, bug or specific behavior question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants