Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for OpenAPI schema generation for POCOs #1087

Closed
captainsafia opened this issue Nov 21, 2022 · 1 comment · Fixed by #1094
Closed

Add support for OpenAPI schema generation for POCOs #1087

captainsafia opened this issue Nov 21, 2022 · 1 comment · Fixed by #1094
Assignees
Labels
goodfirstissue Standard GitHub label used for easy to resolve issues targeting beginner contributors type:enhancement Enhancement request targeting an existing experience
Milestone

Comments

@captainsafia
Copy link
Member

This is related to #836.

For certain native .NET types, it would be great if OpenAPI.NET could provide the authorative OpenApiSchema definitions for these types. Current prototypes maintain a dictionary like this:

private static readonly Dictionary<Type, Func<OpenApiSchema>> _primitiveTypeToOpenApiSchema =
        new()
        {
            [typeof(bool)] = () => new OpenApiSchema { Type = "boolean" },
            [typeof(byte)] = () => new OpenApiSchema { Type = "string", Format = "byte" },
            [typeof(int)] = () => new OpenApiSchema { Type = "integer", Format = "int32" },
            ...
            [typeof(DateTime)] = () => new OpenApiSchema { Type = "string", Format = "date-time" },
            [typeof(DateTimeOffset)] = () => new OpenApiSchema { Type = "string", Format = "date-time" },
            [typeof(Guid)] = () => new OpenApiSchema { Type = "string", Format = "uuid" },
            [typeof(char)] = () => new OpenApiSchema { Type = "string" }
        };

And there a variety of open source packages/projects that maintain their own associations (see this, this, and this).

Since this is a finite set of mappings, it would be great if they would be centralized in the OpenAPI.NET package to avoid duplication and ambiguity about the right schemas to generate for different native types in .NET.

cc: @darrelmiller @baywet

@baywet
Copy link
Member

baywet commented Nov 21, 2022

Additionally, Kiota is doing something similar to get from OpenAPI type/format to dotnet (or other languages) types. Having the opposite dictionary would be helpful as well.

CC @CarolKigoonya to queue this in the pipeline

@baywet baywet added type:enhancement Enhancement request targeting an existing experience goodfirstissue Standard GitHub label used for easy to resolve issues targeting beginner contributors labels Nov 21, 2022
@MaggieKimani1 MaggieKimani1 added this to the NET: 1.4.5 milestone Nov 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
goodfirstissue Standard GitHub label used for easy to resolve issues targeting beginner contributors type:enhancement Enhancement request targeting an existing experience
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants