swagger-api / swagger-editor

Swagger Editor
https://editor.swagger.io
Apache License 2.0
8.91k stars 2.25k forks source link

Sometimes swagger editor cannot expand the typed property of a schema #1932

Open Ark-kun opened 5 years ago

Ark-kun commented 5 years ago

I have a valid JsonSchema. When I use it in OpenAPI3 schema ($ref) some property types fail to expand. If you change the schema slightly, then the original problem might move to another place (the original property starts expanding, but some other property stops expanding). This bug might be related to the circular dependencies in the schema.

Q&A (please complete the following information)

See how componentRef property expands to nothing instead of showing the nested schema. The type of the propertyu is valid and you can check it by replacing "#/definitions/TaskSpec" with "#/definitions/ComponentReference".

Content & configuration

Full OpenAPI definition:

openapi: 3.0.0
info:
  title: Sample API
  version: 0.1.9
paths:
  /pipeline_runs:
    post:
      requestBody:
        content:
          application/json:
            schema:
              $ref: https://raw.githubusercontent.com/kubeflow/pipelines/618b559391a225a6d821141047d6f7438e6f64a1/sdk/python/kfp/components/structures/components.json_schema.json#/definitions/TaskSpec
      responses:
        '200':
          description: Updated

Describe the bug you're encountering

To reproduce...

Steps to reproduce the behavior:

  1. Go to https://editor.swagger.io/
  2. Enter the above schema yaml
  3. Expand /pipeline_runs
  4. Click on Schemas
  5. Try to expand "componentRef"
  6. See that it does not expand

Expected behavior

I expect that the typed properties expand.

Screenshots

image

Additional context or thoughts

P.S. After refreshing the page, the issue was fixed and property started expanding, but I got lots of resolver errors:

Errors
Hide

Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.componentRef.properties.spec.properties.inputs.items.properties.type.oneOf.1.items.$ref
Could not resolve reference: #/definitions/TypeType
Jump to line 11
Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.componentRef.properties.spec.properties.inputs.items.properties.type.oneOf.2.additionalProperties.$ref
Could not resolve reference: #/definitions/TypeType
Jump to line 11
Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.componentRef.properties.spec.properties.implementation.oneOf.0.properties.container.properties.command.items.oneOf.4.properties.concat.items.$ref
Could not resolve reference: #/definitions/CommandlineArgumentType
Jump to line 11
Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.componentRef.properties.spec.properties.implementation.oneOf.0.properties.container.properties.command.items.oneOf.5.properties.if.properties.then.oneOf.0.$ref
Could not resolve reference: #/definitions/CommandlineArgumentType
Jump to line 11
Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.componentRef.properties.spec.properties.implementation.oneOf.0.properties.container.properties.command.items.oneOf.5.properties.if.properties.then.oneOf.1.items.$ref
Could not resolve reference: #/definitions/CommandlineArgumentType
Jump to line 11
Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.componentRef.properties.spec.properties.implementation.oneOf.1.properties.graph.properties.tasks.additionalProperties.$ref
Could not resolve reference: #/definitions/TaskSpec
Jump to line 11
Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.isEnabled.oneOf.6.properties.and.properties.op1.$ref
Could not resolve reference: #/definitions/PredicateType
Jump to line 11
Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.isEnabled.oneOf.6.properties.and.properties.op2.$ref
Could not resolve reference: #/definitions/PredicateType
Jump to line 11
Resolver error at paths./pipeline_runs.post.requestBody.content.application/json.schema.properties.isEnabled.oneOf.8.properties.not.$ref
Could not resolve reference: #/definitions/PredicateType
Jump to line 11
ilcos91 commented 4 years ago

Hi, I'm having the same problem, are there any news?

frisky-lizard commented 4 years ago

Hi, I'm also running into the similar issues.

Running Swashbuckle/Swagger (v5.3.1) on .NET Core 3.1.

The error I was encountering was on a model, containing a reference to the Exception class. This property is decorated with the [JsonIgnore] attribute, and seemed to work fine on older versions of Swagger (doesn't serialise the output) and cannot be seen in the UI.

The errors are exactly in line with those mentioned above by @Ark-kun, however in my case, all the errors are to do with the exposed properties on the Exception class in DNC.

I tried using a schema filter to check for properties that are decorated with the JsonIgnore attribute (that is, the 'Exception' property on my model class), however this doesn't seem to do much when configuring Swagger on startup.

Any insight into this would be hugely appreciated.

--- UPDATE / FIXED ---

This looks like it might not have been the same problem as first described.

I think this came down to a serialisation issue with my model; Swagger was trying to serialise a public property of type Exception, despite using the [JsonIgnore] attribute.

This was fixed by the use of a custom filter, to populate a list of public properties that were decorated with a [JsonIgnore] attribute (as we're talking about .NET Core 3.1 here, you could technically use either the Newtonsoft JsonIgnore attribute or the one native to DNC (System.Text.Json).

These properties can then be removed from the schema. Re-tested, Swagger page loads and I can now view my models and test the endpoints.