OpenAPI.NET icon indicating copy to clipboard operation
OpenAPI.NET copied to clipboard

How load OpenApi split to many files

Open petrkasnal opened this issue 2 years ago • 4 comments

Hello,

I have my OpenAPI specification in separate files. I use references to load data. When I try to do so, I get an exception. {"Unable to cast object of type 'SharpYaml.Serialization.YamlScalarNode' to type 'SharpYaml.Serialization.YamlMappingNode'."}

My openapi looks `openapi: 3.0.3 info: title: 'Test' version: '1.0.0'

components: schemas: $ref: './AllSchemas.yml'

paths: /api/orders: $ref: './orders.yml'`

Can you please help me? Thank you

petrkasnal avatar Mar 28 '23 16:03 petrkasnal

OpenAPI.Net readers currently only have limited support for external files. External files need to be valid OpenAPI documents themselves. Also, $ref in pathItems is a special case that is not supported.

The best option is to preprocess your OpenAPI file using a reference resolver before handing it over to OpenAPI.Net.

darrelmiller avatar Apr 02 '23 15:04 darrelmiller

Thank you for response. Do you think about add this functionality sometime?

petrkasnal avatar Apr 11 '23 10:04 petrkasnal

Yes. We are aiming to fix external references in our v2 version.

darrelmiller avatar May 12 '23 20:05 darrelmiller

Yes. We are aiming to fix external references in our v2 version.

Thank you for reply. And when do you think will be v3 ready? Thank you

petrkasnal avatar May 16 '23 19:05 petrkasnal

The particular examples of referencing that you are using can be addressed using a pre-processing reference resolver. The first example of pulling in a set of schemas in not valid as per the OpenAPI specification, and the second use if $ref in the path is not likely to be supported by this library. I expect that feature to go away in the next major version of OpenAPI.

It would be much better to use a preprocessing tool.

darrelmiller avatar Mar 12 '25 16:03 darrelmiller