tazatechnology / openapi_spec

Dart based OpenAPI specification generator and parser
BSD 3-Clause "New" or "Revised" License
8 stars 5 forks source link

Support oneOf that contains primitive types and objects #31

Closed davidmigloz closed 10 months ago

davidmigloz commented 10 months ago

Currently, if in a oneOf schema there's a mix of primitive types and objects only the primitive types are generated.

Example:

function_call:
  title: ChatCompletionFunctionCall
  description: Controls how the model calls functions. 
  oneOf:
    - type: string
      title: ChatCompletionFunctionCallMode
      enum: [none, auto]
    - $ref: "#/components/schemas/ChatCompletionFunctionCallOption"
ChatCompletionFunctionCallOption:
  type: object
  properties:
    name:
      type: string
      description: The name of the function to call.
  required:
    - name

The generator generates the following class:

@freezed
sealed class ChatCompletionFunctionCall with _$ChatCompletionFunctionCall {
  const ChatCompletionFunctionCall._();

  const factory ChatCompletionFunctionCall.enumeration(
    ChatCompletionFunctionCallMode value,
  ) = _UnionChatCompletionFunctionCallEnum;

  /// Object construction from a JSON representation
  factory ChatCompletionFunctionCall.fromJson(Map<String, dynamic> json) =>
      _$ChatCompletionFunctionCallFromJson(json);
}

Which only contains the ChatCompletionFunctionCall.enumeration factory.