RonnyPfannschmidt / prance

Resolving Swagger/OpenAPI 2.0 and 3.0 Parser
Other
225 stars 43 forks source link

Keep schema name after resolving #151

Open catcombo opened 1 year ago

catcombo commented 1 year ago

Expected Behaviour

Hi and thank you for the great library! I like how it's written and works very stable. Good work!

I try to use ResolvingParser for my custom OpenAPI code generator. The problem is when it resolves references it doesn't keep the referenced schema name in the output spec. Is it possible to provide original schema name to the output or access it somehow with the minimal effort? Or maybe put the name to some custom OpenAPI extension field similar to x-enum-varnames or use existing field (e.g. title)?

{
  "openapi": "3.0.2",
  "info": {
    "title": "Demo",
    "version": "1.0"
  },
  "paths": {
    "/demo": {
      "get": {
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "x-schema-name": "SampleModel",
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}

Minimal Example Spec

api.yml

openapi: '3.0.2'

info:
  title: Demo
  version: '1.0'

paths:
  /demo:
    get:
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: 'demo.yml#/components/schemas/SampleModel'

demo.yml

components:
  schemas:
    SampleModel:
      type: string

Actual Behaviour

{
  "openapi": "3.0.2",
  "info": {
    "title": "Demo",
    "version": "1.0"
  },
  "paths": {
    "/demo": {
      "get": {
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  }
}

Steps to Reproduce

Run prance compile api.yml output.json

Environment

moisesbenzan commented 1 year ago

+1 on this issue. It would be beneficial to have the name of the reference that got evaluated.

andruhamax commented 1 year ago

I also upvote this issue