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

Ignored schema components while generating the types #183

Closed
Zaid-Ajaj opened this issue May 15, 2021 · 4 comments
Closed

Ignored schema components while generating the types #183

Zaid-Ajaj opened this issue May 15, 2021 · 4 comments

Comments

@Zaid-Ajaj
Copy link

Description

While working on Hawaii, I am using a modified PetStore schema and testing with the type provider to see how the results look like and whether I am on the right direction.

For the following schema, the Pet type is completely ignored:

2021-05-15 01_48_48-ConsoleApp17 - Microsoft Visual Studio

Besides Pet, the global UserRole enum seems to also be ignore :

{
  "UserRole": {
      "type": "string",
      "enum": [ "admin", "user" ]
    }
}

and references to that UserRole type in other components (such as User.Role) is resolved to a string instead of an enum

2021-05-15 01_53_31-ConsoleApp17 - Microsoft Visual Studio

Repro steps

Please provide the steps required to reproduce the problem

  1. Create a new console app and add SwaggerProvider v0.12.0 package (1.0.0-beta3 didn't work for me, causing a design time error)
  2. Create the generated types from the schema provided with the link abode
  3. Observe the missing Pet type and UserRole type

Expected behavior

Types are not ignored

Actual behavior

Types are ignored

Known workarounds

None

Related information

  • Operating system: Windows 10
  • Branch: master
  • .NET Runtime: core sdk 5.0.200
  • Performance information, links to performance testing scripts: n/a
@Zaid-Ajaj
Copy link
Author

Zaid-Ajaj commented May 15, 2021

About my comment:

1.0.0-beta003 didn't work for me, this should another issue, really. This happened:

2021-05-15 02_06_38-ConsoleApp17 - Microsoft Visual Studio

Using dotnet 5.0.200 and a console project with default settings

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="petstore.json" />
    <Compile Include="Program.fs" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="SwaggerProvider" Version="1.0.0-beta3" />
  </ItemGroup>

</Project>

Building the project worked but I get the design-time error above when hovering over the reported error in visual studio

@sergey-tihon
Copy link
Member

the Pet type is completely ignored:

in your modified PetStore schema Pet defined as Dictionaty instead of object, that's why object is not generated.

        "Pet": {
            "type": "object",
            "additionalProperties": {
                "type": "integer",
                "format": "int64"
            },

compare it with spec for dictionaries https://swagger.io/docs/specification/data-models/dictionaries/
after merging #174 such object compiled as Map<_,_>

global UserRole enum seems to also be ignore

Swagget/OpenAPI TPs model enums as string, that is why there is no type - #146

1.0.0-beta003 didn't work for me, this should another issue, really. This happened:

What IDE & version do you use?
Looks OK in Microsoft Visual Studio Enterprise 2019 Version 16.9.5
image

@Zaid-Ajaj
Copy link
Author

Hi @sergey-tihon I must have misunderstood the specifications of additional properties because object types using additionalProperties are also allowed to have arbitrary object properties alongside additionalProperties 🤔 at least the schema parsers and validators are perfectly fine when reading the schema and don't report any error.

Maybe I could simplify my implementation 😅

As for the VS type provider error, I will try to see what's going on there, maybe a caching issue because I installed 1.0.0beta3 after 0.12.0 and Vs didn't dispose of loaded assemblies

@Zaid-Ajaj
Copy link
Author

This is what I mean by object properties + additional properties

"Lang": {
    "type": "object",
    "required": [
        "defaultLang"
    ],
    "properties": {
        "defaultLang": {
            "type": "string"
        }
    },
    "additionalProperties": {
        "type": "string"
    }
}

The type Lang is a dictionary of string -> string but will always have a defaultLang property. Generating Map<string, string> is probably good enough but for Hawaii I am having it generate a specialized type

type Lang =
    { defaultLang: string
      additionalProperties: Map<string, string> }

It makes the JSON conversion somewhat more complicated but I already took care of that.

As for the issue, it is resolved since the my schema was a bit too contrived to begin with and the type provider doesn't generate specialized enums

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants