Skip to content

OpenAPI document generation should emit documents with deterministic structure #59809

@mikekistler

Description

@mikekistler

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

The OpenAPI document currently generated by .NET has a non-deterministic ordering of certain features such as path items, tag objects, and possibly other elements. This is problematic in situations where the OpenAPI document is generated at build time and committed to source control, because a small change in the app could generate a diff in the OpenAPI document that is simply a reordering of elements.

An example of the problem is [this PR in the eShop project], where the diff of the src/Catalog.API/Catalog.API.json file shows:

>git diff --stat main src/Catalog.API/Catalog.API.json 
 src/Catalog.API/Catalog.API.json | 602 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------------------------------------------------------------
 1 file changed, 306 insertions(+), 296 deletions(-)

but by sorting the files with jq, we can see that the substantive changes are much smaller:

>diff <(git show main:src/Catalog.API/Catalog.API.json | jq --sort-keys .) <(jq --sort-keys . src/Catalog.API/Catalog.API.json) 
379a380,389
>           "400": {
>             "content": {
>               "application/json": {
>                 "schema": {
>                   "$ref": "#/components/schemas/ProblemDetails"
>                 }
>               }
>             },
>             "description": "Bad Request"
>           },
968,970d977
<       "name": "Search"
<     },
<     {
974a982,984
>     },
>     {
>       "name": "Search"

Here only the 400 response is substantive -- the other change is a recording of the tag objects which isn't remedied by the --sort-keys feature of jq.

Describe the solution you'd like

The framework should generate the OpenAPI document with a deterministic structure, such that changes to the app will produce a new document with minimal and only "substantive" changes in the textual diff.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions