microsoft / kiota-typescript

TypeScript libraries for Kiota-generated API clients.
https://aka.ms/kiota/docs
MIT License
37 stars 27 forks source link

Required Properties should be applied to models' type (but not) #1101

Closed yasaichi closed 7 months ago

yasaichi commented 7 months ago

Thanks for working on the great libary! Recently I have finished the quick start tutorial and found that the generated code for models doesn't follow OpenAPI specification.

Repro steps

  1. Change the properties of post component in this example to required ones:
components:
  schemas:
    post:
      type: object
      properties:
        userId:
          type: integer
        id:
          type: integer
        title:
          type: string
        body:
          type: string
      required:
        - userId
        - id
        - title
        - body
  1. Run the following command:
$ kiota --version
1.12.0+1735a2ff916ebec661974d9560f1dd00d3dc349b

$ kiota generate --co -l typescript -d posts-api.yml -c PostsClient -o ./client 

Expectated code

// client/models/index.ts
export interface Post extends AdditionalDataHolder, Parsable {
    /**
     * Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
     */
    additionalData?: Record<string, unknown>;
    /**
     * The body property
     */
    body: string;
    /**
     * The id property
     */
    id: number;
    /**
     * The title property
     */
    title: string;
    /**
     * The userId property
     */
    userId: number;
}

Actual code

// client/models/index.ts
export interface Post extends AdditionalDataHolder, Parsable {
    /**
     * Stores additional data not described in the OpenAPI description found when deserializing. Can be used for serialization as well.
     */
    additionalData?: Record<string, unknown>;
    /**
     * The body property
     */
    body?: string;
    /**
     * The id property
     */
    id?: number;
    /**
     * The title property
     */
    title?: string;
    /**
     * The userId property
     */
    userId?: number;
}
baywet commented 7 months ago

Hi @yasaichi Thanks for the praises, and for using kiota. This is an ongoing topic, we've already had a lot of discussions here https://github.com/microsoft/kiota/issues/3911 Can I suggest you join the conversation over there so it's centralized? Closing.

yasaichi commented 7 months ago

@baywet Thanks for telling me the related issue! I'll see that later.