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

Add support for extending OpenApi info object via extensions #3446

Closed
3 tasks done
irvinesunday opened this issue May 24, 2024 · 2 comments · Fixed by #3626
Closed
3 tasks done

Add support for extending OpenApi info object via extensions #3446

irvinesunday opened this issue May 24, 2024 · 2 comments · Fixed by #3626
Assignees
Labels
design:needed A design request has been raised that needs a proposal feature New feature or request lib:openapi triaged:core
Milestone

Comments

@irvinesunday
Copy link
Contributor

Clear and concise description of the problem

Given the below Typespec example, which passes a custom decorator @skill() on a namespace that aims to extend the OpenApi info object via extensions:

main.tsp

import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi3";
// IMPORTED CUSTOM SKILLS DECORATOR

using TypeSpec.Http;
using TypeSpec.Rest;
// using TypeSpec.Skills; (uncomment when ready)

alias sunoSkill = {
  name_for_human: "Suno";
  description_for_human: "Suno is a tool that can generate songs based on a description. The user provides a description of the song they want to create, and Suno generates the song lyrics. Suno is a fun and creative way to create songs for any occasion.";
  logo_url: "https://th.bing.com/th?id=OSK.935650835684F7E18AC3F31034DE6DF3";
  contact_email: "ionutro@microsoft.com";
  privacy_policy_url: "https://app.suno.ai/privacy";
  legal_info_url: "https://app.suno.ai/legal";
};

/**
 * Suno is a tool that can generate songs based on a description. The user provides a description of the song they want to create, and Suno generates the song lyrics. Suno is a fun and creative way to create songs for any occasion.
 */
@service({
  title: "Suno"
})
@skill(sunoSkill)
@route("/createSong")
namespace Suno {
  /** Create a song given the user preferences */
  @get op createSong(
    /** The requested song description, eg. `a country song about Thanksgiving` */
    @query topic: string): string;
}

The expected OpenApi file output should be:

openapi.yaml

openapi: 3.0.0
info:
  title: Suno
  description: Create any song you want based on a description
  version: 1.0.0
  contact:
    email: ionutro@microsoft.com
  x-logo: https://w7.pngwing.com/pngs/208/848/png-transparent-musical-note-logo-clef-music-logo-design-other-text-musical-composition.png
  x-ai-description: Suno is a tool that can generate songs based on a description. The user provides a description of the song they want to create, and Suno generates the song lyrics. Suno is a fun and creative way to create songs for any occasion.
  x-legal-info-url: https://app.suno.ai/legal
  x-privacy-policy-url: https://app.suno.ai/privacy
tags: []
paths:
  /createSong:
    get:
      operationId: createSong
      description: Create a song given the user preferences
      parameters:
        - name: topic
          in: query
          required: true
          description: The requested song description, eg. `a country song about Thanksgiving`
          schema:
            type: string
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                type: string
components: {}

However, this is currently not supported. We need to have a way of extending an OpenApi info object via extensions.

Checklist

  • Follow our Code of Conduct
  • Read the docs.
  • Check that there isn't already an issue that request the same feature to avoid creating a duplicate.
@markcowl markcowl added the design:needed A design request has been raised that needs a proposal label Jun 3, 2024
@markcowl markcowl added this to the [2024] July milestone Jun 3, 2024
@markcowl markcowl added feature New feature or request triaged:core labels Jun 3, 2024
@timotheeguerin
Copy link
Member

The implementation of this should basically be the same as setExtension helper.

but setInfoExtension(key: string, value: unknown): void and then add those values to the info data

@wanlwanl
Copy link
Member

Maybe it can be workaround for now? @irvinesunday
Typespec:

import "@typespec/http";
import "@typespec/rest";
import "@typespec/openapi";
import "@typespec/openapi3";

using TypeSpec.Http;
using TypeSpec.Rest;
using TypeSpec.OpenAPI;

/**
 * This is a sample server Petstore server.
 */
@info({
    title: "title - info",
    "x-cutome-info": {
        name_for_human: "Suno";
        description_for_human: "Suno is a tool that can generate songs based on a description. The user provides a description of the song they want to create, and Suno generates the song lyrics. Suno is a fun and creative way to create songs for any occasion.";
        logo_url: "https://th.bing.com/th?id=OSK.935650835684F7E18AC3F31034DE6DF3";
        contact_email: "ionutro@microsoft.com";
        privacy_policy_url: "https://app.suno.ai/privacy";
        legal_info_url: "https://app.suno.ai/legal";
      },
})
@service
namespace PetStore;

@extension("x-custom", "My value")
op readxxx(): string;

Result:

openapi: 3.0.0
info:
  title: title - info
  x-cutome-info:
    name_for_human: Suno
    description_for_human: Suno is a tool that can generate songs based on a description. The user provides a description of the song they want to create, and Suno generates the song lyrics. Suno is a fun and creative way to create songs for any occasion.
    logo_url: https://th.bing.com/th?id=OSK.935650835684F7E18AC3F31034DE6DF3
    contact_email: ionutro@microsoft.com
    privacy_policy_url: https://app.suno.ai/privacy
    legal_info_url: https://app.suno.ai/legal
  description: This is a sample server Petstore server.
  version: 0.0.0
tags: []
paths:
  /:
    get:
      operationId: readxxx
      parameters: []
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                type: string
      x-custom: My value
components: {}

github-merge-queue bot pushed a commit that referenced this issue Jul 9, 2024
Fixes #3446

By adding support for extending namespace, we will be able to add
extensions to the OpenAPI `info` object via the new function -
`setNamespaceExtension(...)`

---------

Co-authored-by: Timothee Guerin <timothee.guerin@outlook.com>
Co-authored-by: Timothee Guerin <tiguerin@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design:needed A design request has been raised that needs a proposal feature New feature or request lib:openapi triaged:core
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants