Skip to content

Keep schema name after resolvingΒ #151

@catcombo

Description

@catcombo

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

  • OS: Fedora 37
  • Python version: 3.11.2
  • Swagger/OpenAPI version used: 3.0.2
  • Backend: openapi-spec-validator

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions