Skip to content

Conversation

@annelo-msft
Copy link

The original OpenAI API definition defines their auth policy as API Key, so changing the TypeSpec to do the same.

@@ -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.

main.tsp Outdated
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

annelo-msft referenced this pull request in annelo-msft/openai-in-typespec Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants