Skip to content

No simple way to convert formats while keeping OpenAPI spec version the same #172

Closed

Description

@scott-lin

I'd like to simply convert between OpenApiFormat while keeping OpenApiSpecVersion the same across the conversion, however, there is no way of doing this that avoids me having to parse the OpenApiSpecVersion from the string payload myself.

For example, below is some basic code to demonstrate the scenario and issue. In this example, we'd be converting YAML string -> OpenApirDocument model -> JSON string.

string documentYaml = "some YAML OpenApi document payload";

var openApiStringReader = new OpenApiStringReader();
OpenApiDocument openApiDocument = openApiStringReader.Read( documentYaml, out 
OpenApiDiagnostic openApiDiagnostic );

string documentJson = openApiDocument.SerializeAsJson(???);

What is the recommended way of getting to know the OpenApiSpecVersion to pass to SerializeAsJson (respresented by ??? above) in order to keep the version consistent.

Activity

  1. darrelmiller commented on Jan 10, 2018

    @darrelmiller
    Member

    We would need to add a property to the OpenApiDiagnostic object to store the "detected input version". This could then be used to select the output format. I'm not sure how to make that completely transparent though.

  2. scott-lin commented on Jan 10, 2018

    @scott-lin
    ContributorAuthor

    I like the idea. I don't like the name of OpenApiDiagnostic since not all of the data is "diagnostic" data. OpenApiMetadata might be better since it's data that helps describe the OpenApiDocument generated.

    Also, what do you mean by, "I'm not sure how to make that completely transparent though"?

  3. darrelmiller commented on Jan 10, 2018

    @darrelmiller
    Member

    Scott Lin (@scott-lin) I mean that you would need to take the value from the "diagnostic" object and the pass it into the Serialize method manually.
    I'm not a big fan of the name diagnostic either but metadata is not much better. We need a word that means meta-results but is less ugly.

  4. PerthCharern commented on Jan 10, 2018

    @PerthCharern
    Contributor

    Maybe something like OpenApiReaderMetadata / OpenApiReadingMetadata since it's a metadata of the reading process?

  5. scott-lin commented on Jan 10, 2018

    @scott-lin
    ContributorAuthor

    I will start coding the fix we all have agreed on (parse the version from the document as an OpenApiSpecVersion and assign it as a property on OpenApiDiagnostic).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions