kiota icon indicating copy to clipboard operation
kiota copied to clipboard

Support Property References

Open JustinGrote opened this issue 1 year ago • 8 comments

Attempting to use the OpenAI specification here: kiota download apisguru::openai.com -o openai.spec.json

Fails with

fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/logit_bias' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateSearchRequest/properties/return_metadata' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/user' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/user' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateAnswerRequest/properties/expand' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/logit_bias' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateAnswerRequest/properties/logprobs' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/model' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateSearchRequest/properties/return_metadata' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateAnswerRequest/properties/return_prompt' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateAnswerRequest/properties/search_model' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/user' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/model' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/user' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateImageRequest/properties/n' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateImageRequest/properties/response_format' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateImageRequest/properties/size' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/user' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/user' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateImageRequest/properties/n' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateImageRequest/properties/response_format' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateImageRequest/properties/size' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/user' has invalid format.
fail: Kiota.Builder.KiotaBuilder[0]
      OpenAPI error: (null) - The reference string '/components/schemas/CreateCompletionRequest/properties/user' has invalid format.
crit: Kiota.Builder.KiotaBuilder[0]

I believe this is because it is a reference to a property and maybe kiota doesn't support that yet? Works just fine in other generators.

JustinGrote avatar Mar 06 '23 22:03 JustinGrote

Hi @JustinGrote. Thanks for your interest in Kiota and for reaching out. We're using OpenAPI.net to parse OpenAPI descriptions and the issue comes from here

"user": {
            "$ref": "#/components/schemas/CreateCompletionRequest/properties/user"
          }

This property defined in one component schema is referencing another component schema property. I'm not sure whether this is a valid reference or not and I'm trying to get clarity with @darrelmiller. Either it's a valid reference and OpenAPI.net doesn't support it. In which case I'll transfer the issue over there to address it. Or it's invalid in which case the description would need to be updated. Spectral doesn't seem to be complaining about it, which would lead me to think it's valid.

baywet avatar Mar 07 '23 15:03 baywet

Also as a side note, I believe you meant to mention the generate command and not the download one as the download one doesn't do any kind of parsing.

baywet avatar Mar 07 '23 15:03 baywet

Also as a side note, I believe you meant to mention the generate command and not the download one as the download one doesn't do any kind of parsing.

You are correct, thanks, and nswag generates a client properly including these property references.

JustinGrote avatar Mar 07 '23 15:03 JustinGrote

Follow up, @darrelmiller do you know where this needs to land? Again nswag handles it just fine, I'm using it here but would be open to trying Kiota if I can get this item fixed because it's fairly pervasive in the spec, and the swagger.io editor doesn't show any errors when opening it so I assume that it is to spec. https://github.com/JustinGrote/PowerShellAssistant/tree/main/src/OpenAI.Client

EDIT: A newer spec has been published here that removes the property references: https://github.com/openai/openai-openapi/blob/master/openapi.yaml

This one also does not generate due to the following error, but that's a separate issue.

crit: Kiota.Builder.KiotaBuilder[0]
      error generating the client: One or more errors occurred. (Error creating property expand for model CreateClassificationRequest in API path \classifications, the schema is invalid.) (Error creating property expand for model CreateAnswerRequest in API path \answers, the schema is invalid.)

Excluding the \classifications and \answers endpoints with --exclude-path seems to allow the client to build fine at that point.

JustinGrote avatar Mar 21 '23 18:03 JustinGrote

The OpenAPI specification states that $ref can be used to point to components. OpenAPI.net has interpreted that to mean that $ref cannot point to sub-schemas of components.

We still have issues with the oneOf in the completion response of the OpenAI api and the schemas that define an array of empty schemas. I'm thinking of doing a PR to their OpenAPI to fix that.

darrelmiller avatar Mar 25 '23 19:03 darrelmiller

Thanks for the context @darrelmiller . Should we transfer this to the openapi.net for further discussion and potential resolution?

baywet avatar Mar 26 '23 20:03 baywet

@baywet We don't have plans to support non-component $refs in OpenAPI.Net. I would like to keep an issue open related to being able to support OpenAI API. The issue that @JustinGrote is experiencing has been resolved in the latest build. However, now we have this issue https://github.com/microsoft/kiota/issues/2462

I will create a new issue that is a meta issue for supporting OpenAI.

darrelmiller avatar Mar 26 '23 21:03 darrelmiller

@darrelmiller where are we with this issue? Do we have enhancements that improved this situation?

sebastienlevert avatar Feb 01 '24 14:02 sebastienlevert