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

properties named "nullable" and subschema components #261

Open
fradav opened this issue Feb 9, 2025 · 0 comments
Open

properties named "nullable" and subschema components #261

fradav opened this issue Feb 9, 2025 · 0 comments

Comments

@fradav
Copy link

fradav commented Feb 9, 2025

It’s basically two issues in one: the inability to parse the openapi v3 schema from https://cloud.squidex.io/ (a very nice .net CMS by the way)
Here I provide a script which reproduces the issues, see the comment./
For the nullable named property, re-serializing the schema with Microsoft.OpenApi is a workaround (hence the outputSchemaV3 function to do that.
Anyway, “subcomponent” schema (subschema?) are not parsed or correctly taken into account, see the last comment.

convertedcomponent-schema.json
nullablepropertyandcomponent-schema.json
converted-schema.json
nullableproperty-schema.json

#r "nuget: Microsoft.OpenApi.Readers"
#r "nuget: Microsoft.OpenApi"

open Microsoft.OpenApi.Readers
open Microsoft.OpenApi.Writers
open System.IO

let outputSchemaV3 origin converted =

    let convertedPath = __SOURCE_DIRECTORY__ + "/" + converted
    use convertedStream = File.Create(convertedPath)
    use streamWriter = new StreamWriter(convertedStream)
    let jsonWriter = new OpenApiJsonWriter(streamWriter)

    let openApiDocumentReader = new OpenApiStreamReader()
    let oriiginPath = __SOURCE_DIRECTORY__ + "/" + origin
    use readerStream = File.OpenRead(oriiginPath)

    readerStream |> openApiDocumentReader.Read |> fst |> _.SerializeAsV3(jsonWriter)

    streamWriter.Flush() // Ensure all data is written to the file

outputSchemaV3 "nullableproperty-schema.json" "converted-schema.json"
outputSchemaV3 "nullablepropertyandcomponent-schema.json" "convertedcomponent-schema.json"

#r "nuget: SwaggerProvider"

open SwaggerProvider

[<Literal>]
let schemaPath = __SOURCE_DIRECTORY__ + "/nullableproperty-schema.json"

[<Literal>]
let convertedSchemaPath = __SOURCE_DIRECTORY__ + "/converted-schema.json"

[<Literal>]
let convertedComponentSchemaPath =
    __SOURCE_DIRECTORY__ + "/convertedcomponent-schema.json"

// type BlogApi = OpenApiClientProvider<schemaPath>
// The type provider 'SwaggerProvider.OpenApiClientTypeProvider' reported an error: Schema parse errors:
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}/get/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}/post/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}/put/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}/patch/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}/delete/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}~1{version}/get/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}~1{version}/get/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}~1validity/get/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}~1defaults/put/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1pages~1{id}~1status/put/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}/get/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}/post/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}/put/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}/patch/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}/delete/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}~1{version}/get/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}~1{version}/get/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}~1validity/get/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}~1defaults/put/parameters @
// nullable is not a valid property at #/paths/~1api~1content~1fradav-blog~1posts~1{id}~1status/put/parameters @


type BlogApi = OpenApiClientProvider<convertedSchemaPath>

let page = BlogApi.PagesContentDto()
page.Data <- BlogApi.PagesDataDto()
page.Data.Title <- Map [ "iv", "Hello, world!" ]
// OK

type BlogApiComponent = OpenApiClientProvider<convertedComponentSchemaPath>

let alternativeTitleComponent =
    BlogApiComponent.PagesDataDto_AlternativeTitle_Item()
// alternativeTitleComponent.Title <- Map [ "iv", "Hello, world!" ] // Not OK, Title should be a property of the component
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

1 participant