-
Notifications
You must be signed in to change notification settings - Fork 334
feat(openapi3): add x-ms-duration extension support for duration encoding with round-trip via @extension decorator #9412
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
base: main
Are you sure you want to change the base?
Conversation
…with @encode decorator Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
|
@copilot add another unit test to validate there are no regressions if it does not exist already. The following OpenAPI description foo:
type: string
format: durationShould result in this TypeSpec bar: durationNote there are no encode attribute in that case. |
commit: |
Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Added regression test in commit 09b3593. The test validates that |
|
You can try these changes here
|
Pull request was converted to draft
Implemented in commit d7f45bd. The OpenAPI emitter now adds the |
|
@copilot revert the change where the encode decorator generates the extension. Instead make sure the import also adds an extension decorator when the extension is present in the source document. |
…d of auto-generating extension - Revert export functionality that auto-generated x-ms-duration extension - Update import to add @extension decorator when x-ms-duration is present - Both @extension and @encode decorators are now added during import - Removes extension filtering for x-ms-duration - Update tests to expect both decorators - Enables proper round-tripping via @extension decorator Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Reverted export functionality in commit 3eab35d. The importer now adds both |
|
@copilot while running integration tests, I'm running into the following issue, regardless of the format, the encode as is always float32. Investigate and correct this behaviour. |
…encoding format - Pass effectiveType to getDurationSchemaDecorators to handle OpenAPI 3.1 type arrays - Fixes issue where format was always float32 regardless of actual format - Update test expectations to match TypeSpec compiler's decorator ordering - Now correctly generates int32, float32, float64, decimal based on schema format Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Fixed in commit 446c2e1. The issue was that |
|
@copilot Add a data-types test for this format combination: type: number
format: int64
x-ms-duration: secondsThe result should be |
… with x-ms-duration - Add support for integer formats (int8, int16, int32, int64, uint8, uint16, uint32, uint64) when type is number - Fixes scenario where type: number, format: int64, x-ms-duration: seconds now correctly generates @encode("seconds", int64) - Add test case for number with int64 format and x-ms-duration extension - All 33 data-types tests pass Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
... Added test in commit 8772da4. The test initially failed (was generating |
OpenAPI duration property import with x-ms-duration extension
This PR implements support for duration types in the OpenAPI importer using the
x-ms-durationextension, with round-trip capability via the@extensiondecorator.Changes completed:
Implementation details:
Import (OpenAPI → TypeSpec):
getNumberType()andgetIntegerType()ingenerate-types.tsto check forx-ms-durationextension (values:secondsormilliseconds)getDurationSchemaDecorators()function indecorators.tsto:effectiveTypeparameter to properly handle OpenAPI 3.1 type arrays like["integer", "null"]@encodedecorators based on both thex-ms-durationvalue and the schema's formatx-ms-durationfromgetExtensions()so it's also added as an@extensiondecorator for proper round-trippingExport (TypeSpec → OpenAPI):
@extensiondecorator mechanism@extension("x-ms-duration", "seconds"), the standard extension handling emits it to OpenAPITest coverage:
data-types.test.tscovering all import scenarios from requirements table (33 tests)generate-type.test.tsfor inline type expressions (82 tests)Supported scenarios:
durationint32@extension("x-ms-duration", "seconds") @encode("seconds", int32) ... duration@extension("x-ms-duration", "seconds") @encode("seconds", int64) ... durationfloat32@extension("x-ms-duration", "seconds") @encode("seconds", float32) ... duration@extension("x-ms-duration", "seconds") @encode("seconds", decimal) ... duration@extension("x-ms-duration", "milliseconds") @encode("milliseconds", float64) ... durationExample transformations:
Integer type with int32 format:
Number type with int64 format:
Number type with decimal format:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.