Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Is it psossible to make version selection a dropdown instead of text entry in Swagger? #1088

Discussion options

image

I am curious whether it's possible to make it a fixed list of avialable versions.

You must be logged in to vote

Yes - it is possible. In the example project, change the line:

parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson( json );

to

parameter.Schema.Enum = [OpenApiAnyFactory.CreateFromJson( json )];

This will yield the API version as an enumeration.

It should be noted that the documented API may not be representative of all API versions. The model, parameters, and so on may be different across API versions, even if the URL is the same (which it should be). You can use the supported API versions to produce a full list, but realize that this is for the entire API…

Replies: 2 comments

Comment options

Or maybe it can have one fixed value defined by the selection:
image

You must be logged in to vote
0 replies
Comment options

Yes - it is possible. In the example project, change the line:

parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson( json );

to

parameter.Schema.Enum = [OpenApiAnyFactory.CreateFromJson( json )];

This will yield the API version as an enumeration.

image

It should be noted that the documented API may not be representative of all API versions. The model, parameters, and so on may be different across API versions, even if the URL is the same (which it should be). You can use the supported API versions to produce a full list, but realize that this is for the entire API (ex: the Orders API) and not a specific endpoint. It is possible that an endpoint may not exist in a supported API version.

If that doesn't apply to you or you don't care about that limitation, you can list all supported API versions like so:

var metadata = apiDescription.ActionDescriptor.GetApiVersionMetadata();
var model = metadata.Map( ApiVersionMapping.Explicit | ApiVersionMapping.Implicit );

parameter.Schema.Enum =
    model.SupportedApiVersions.Select(
        version => OpenApiAnyFactory.CreateFromJson(
                    JsonSerializer.Serialize(
                        version.ToString(),
                        modelMetadata.ModelType ) ) ).ToImmutableArray();

parameter.Schema.Default =
    OpenApiAnyFactory.CreateFromJson(
        JsonSerializer.Serialize(
            description.DefaultValue,
            modelMetadata.ModelType ) );

This will also continue to set the default value so that the default selection is whichever API version you are currently viewing.

image

I hope that helps.

You must be logged in to vote
0 replies
Answer selected by voroninp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
2 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.