We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
TypeSpec converts "no" enum strings to "False", which is incorrect.
This is the so-called Norway Problem:
countries: - GB - NO // Becomes false
The safest way would be to use "string" quotes for enum string values that convert to a boolean, case-insensitive:
y|yes|n|no|true|false|on|off
This TypeSpec file:
@service({}) namespace Main; enum Countries { GB: "gb", NO: "no", // !!! Norway problem }
gets compiled into this OpenAPI:
components: schemas: Countries: type: string enum: - gb - no # !!! Becomes boolean "false", but must be a string
Playground: link
Or compile locally this way:
$ npm install @typespec/compiler @typespec/openapi3 $ tsp compile --emit @typespec/openapi3 .
The text was updated successfully, but these errors were encountered:
@kolypto I try it in Playground, but it looks like want you want. Could you double confirm?
Sorry, something went wrong.
@wanlwanl it looks alright, but it won't work alright :)
Indeed, the Yaml list is rendered this way:
enum: - gb - no
However, in Yaml, this will result in this JSON: [ "gb", false ] because no in Yaml is a boolean value! :) It should be quoted in the output:
[ "gb", false ]
no
enum: - gb - "no"
@kolypto Thank you for your explanation. This is indeed related to the YAML standard specifications. YAML 1.1 treats yes/no as boolean values, while YAML 1.2 does not. The issue in typespec should indeed be addressed to support YAML 1.1 properly. For now, a temporary workaround could be explicitly specifying YAML version 1.2.x doc section 1.6.8. FYI: https://yaml.org/spec/1.1/current.html#id864510 https://yaml.org/spec/1.2.2/#3232-scalar-formats https://perlpunk.github.io/yaml-test-schema/schemas.html
No branches or pull requests
Describe the bug
TypeSpec converts "no" enum strings to "False", which is incorrect.
This is the so-called Norway Problem:
The safest way would be to use "string" quotes for enum string values that convert to a boolean, case-insensitive:
Reproduction
This TypeSpec file:
gets compiled into this OpenAPI:
Playground: link
Or compile locally this way:
$ npm install @typespec/compiler @typespec/openapi3 $ tsp compile --emit @typespec/openapi3 .
Checklist
The text was updated successfully, but these errors were encountered: