Comments (14)
Yeah for the 2nd point I would say that if you have
alias Stuff = [float64, string];
you get the following openapi3 + a warning
type: array
items:
anyOf:
- type: number
format: double
- type: string
minLength: 2
maxLength: 2
from cadl.
In practice I haven't seen anyone generating tuples from openAPI with length constraints, though I haven't looked super broadly. It would need to be heuristic though, the tuple type for @minLength(1000) @maxLength(2000)
would be ridiculous 😂
from cadl.
I guess we don't have a good support for tuples in openapi3 and not sure what we should generate here. In this specific case we could treat it as an array of part with length 1 but if you lets say have [A, B]
it is a bit more complex.
from cadl.
I thought I recalled implementing this in JSON Schema, but I don't see that it's supported (crash in #2460 aside). I think a reasonable representation of tuples in JSON Schema is using an array type with a fixed length and each element's schema defined with prefixItems
. I don't know if prefixItems
is reasonable for OpenAPI 3.0 though, thoughts @mikekistler?
from cadl.
I don't think it is an option for openapi3 but for 3.1 it does seems to be the way
For 3.0 we'd have to make it a oneOf
all the options and of the length of the tuple
from cadl.
I guess I didn't realize that this was valid syntax. This represents a tuple? Where are the docs for tuple?
from cadl.
Looks like they are not documented under language basics and should be. They come up for various decorators which expect them, however.
from cadl.
- Separate issues for OpenAPI. - 5
- Fixing EF to not crashing (track in other issue)
- Supporting tuple declaration in JSON Schema - 5
from cadl.
For 3.0 we'd have to make it a oneOf all the options and of the length of the tuple
I think that for 3.0 it should just be an error.
from cadl.
Feels a little strong to me to be an error, specially in cases where you have something like
alias Point2D = [float64, float64];
this can be acurrately represented with
type: array
items:
type: number
format: double
minLength: 2
maxLength: 2
My vote would be:
- If all the types in the tuple are the same, represent it as above with no error
- If types are different emit a warning and use
anyOf
from cadl.
For your last bullet, just to be clear, are you saying the items
schema is anyOf the tuple types? If so, I think that sounds reasonable. the oneOf
above seems cool but I suspect the codegen from that wouldn't be pretty.
@mikekistler can you say more about why an error is appropriate here? I think in general we should strive to emit something for all TypeSpec unless there's a very good reason not to.
from cadl.
Also, just want to point out that tuples are not exactly that exotic. E.g. GeoJSON defines Position
as an array of exactly length 2 or 3, where the indexes correspond to long, lat, and optionally elevation, respectively. A type like:
model Geo {
coordinates: [float64, float64] | [float64, float64, float64]
}
would give better codegen for languages that support such types (and would be even more terse if we supported optional tuple elements, which I imagine we will one day!), over something like:
model Geo {
@minLength(2)
coordinates: float64[];
}
from cadl.
@timotheeguerin I feel like we should leave the maxLength
out actually, that feels like as if we added additionalProperties: false
to every schema... The tuple demands you provide at least those elements, any extra elements might be sent and likely ignored?
from cadl.
I guess but also if you were to look at the openapi/jsonschema for that and not see the maxLength it would look like any array and not sure you would ever regenerate a tuple seeing that
from cadl.
Related Issues (20)
- Add support to generate a model as struct instead of class in csharp
- Adding `DebuggerDisplay` to expressions, statements, snippets and output types to provide a friendly debugging experience
- [Bug]: @doc on bytes doesn't output OpenAPI description
- Add method in `TypeFactory` to get a `ModelTypeProvider` or `EnumTypeProvider`
- MGC is not clearing output folder before writing new files HOT 1
- [Bug]: `1.0` is returned as `int32` type in enum values HOT 1
- Consider converting newarrayexpression and newdictexpression to snippet
- Consider consolidating parameterreference, variablereference, etc
- Update the models to consume ChangeTrackingList and ChangeTrackingDictionary types
- Integrated Document Generator for TypeSpec
- Implement `disable-xml-docs` configuration
- [Bug]: VSCode extension fails to find node or tsp-server in PATH HOT 5
- Versioning for 3p libraries
- Update the models and enums to utilize Argument types
- [Bug]: Incorrect PATCH request schema HOT 1
- Move Parameter Validation to Method Body Construction
- [Bug]: Nullable Generic Type in CSharpType Returns Incorrect Type
- Let compiler CLI output results as JSON HOT 1
- Consider output type prefix suffix for class designation
- [Bug]: JSON Schema emitter mismatched $ref when using a Record<T> type HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cadl.