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

Change from BearerAuth to API Key Auth #3

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions conversion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
A conversion of the OpenAI OpenAPI to TypeSpec.

There are some deltas:

### Changes to API Semantics:

- Many things are missing defaults (mostly due to bug where we can't set null defaults)
- Error responses have been added.
- Where known, the `object` property's type is narrowed from string to the constant value it will always be

### Changes to API metadata or OpenAPI format

- Much of the x-oaiMeta entries have not been added.
- In some cases, new schemas needed to be defined in order to be defined in TypeSpec (e.g. because the constraints could not be added to a model property with a heterogeneous type)
- There is presently no way to set `title`
2 changes: 1 addition & 1 deletion main.tsp
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ using TypeSpec.Http;
},
version: "2.0.0",
})
@useAuth(BearerAuth)
@useAuth(ApiKeyAuth<ApiKeyLocation.query, "AUTHORIZATION">)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bterlson, is there a way to tell the ApiKeyAuth piece about a string prefix it needs to add before the API key?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@timotheeguerin timotheeguerin Sep 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is a bearerkey defined in the original api though

https://github.com/openai/openai-openapi/blob/58fee4955e93bb5762ec612126441330a044f5d2/openapi.yaml#L2199

 securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: 'bearer'

ApiKeyAuth is just a free name they choosed

See playground with BearerAuth
vs ApiKeyAuth

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exact same name can be achieved by using your own model name instead of BearerAuth if this is important

import "@typespec/http";

using TypeSpec.Http;

@service
@useAuth(ApiKeyAuth)
namespace DemoService;

model ApiKeyAuth is BearerAuth {}

https://cadlplayground.z22.web.core.windows.net/?c=aW1wb3J0ICJAdHlwZXNwZWMvaHR0cCI7Cgp1c2luZyBUeXBlU3BlYy5IdHRwOwoKQHNlcnZpY2UKQHVzZUF1dGgoQXBpS2V5xAspCm5hbWVzcGFjZSBEZW1vU8YrOwoKbW9kZWwgyiogaXMgQmVhcmVyxQ57fQ%3D%3D&e=@typespec/openapi3&options=%7B%22linterRuleSet%22:%7B%22extends%22:%5B%22@typespec/http/all%22%5D%7D%7D

namespace OpenAI;
16 changes: 2 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
A conversion of the OpenAI OpenAPI to TypeSpec.
# OpenAPI spec for the OpenAI API
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a weird Windows thing, we think, and I can follow up by deleting this file, which I've moved to conversion.md.


There are some deltas:

### Changes to API Semantics:

- Many things are missing defaults (mostly due to bug where we can't set null defaults)
- Error responses have been added.
- Where known, the `object` property's type is narrowed from string to the constant value it will always be

### Changes to API metadata or OpenAPI format

- Much of the x-oaiMeta entries have not been added.
- In some cases, new schemas needed to be defined in order to be defined in TypeSpec (e.g. because the constraints could not be added to a model property with a heterogeneous type)
- There is presently no way to set `title`
This repository contains an [OpenAPI](https://www.openapis.org/) specification for the [OpenAI API](https://platform.openai.com/docs/api-reference).