stanisław
stanisław
Explore posts from servers
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
I will do it @ArkDavid if not today then on the weekend
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
It would be useful to look at this zod to json schema as it looks battle tested and make the outputs similar so the tools like open api work properly
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
sure thanks for help
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
and there is a transform
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
await server.register(import("@fastify/swagger"), {
openapi: {
info: {
title: "Docs",
version: "1.0.0",
}
},
transform: (item) => {
const { response, headers, querystring, body, params, ...rest } = item.schema

if (response) {
for (const status in response as Record<string, unknown>) {
// @ts-expect-error -- That's ok it should be an object with status codes as keys
const responseSchema = response[status] as unknown


// @ts-expect-error -- That's ok it should be an object with status codes as keys
// eslint-disable-next-line
response[status] = responseSchema instanceof Type ? responseSchema.toJsonSchema() : arkSchema
}
}

return {
...item,
schema: {
...rest,
response,
headers: headers instanceof Type ? headers.toJsonSchema() : headers,
querystring: querystring instanceof Type ? querystring.toJsonSchema() : querystring,
body: body instanceof Type ? body.toJsonSchema() : body,
params: params instanceof Type ? params.toJsonSchema() : params,
}
}
}
})
await server.register(import("@fastify/swagger"), {
openapi: {
info: {
title: "Docs",
version: "1.0.0",
}
},
transform: (item) => {
const { response, headers, querystring, body, params, ...rest } = item.schema

if (response) {
for (const status in response as Record<string, unknown>) {
// @ts-expect-error -- That's ok it should be an object with status codes as keys
const responseSchema = response[status] as unknown


// @ts-expect-error -- That's ok it should be an object with status codes as keys
// eslint-disable-next-line
response[status] = responseSchema instanceof Type ? responseSchema.toJsonSchema() : arkSchema
}
}

return {
...item,
schema: {
...rest,
response,
headers: headers instanceof Type ? headers.toJsonSchema() : headers,
querystring: querystring instanceof Type ? querystring.toJsonSchema() : querystring,
body: body instanceof Type ? body.toJsonSchema() : body,
params: params instanceof Type ? params.toJsonSchema() : params,
}
}
}
})
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
https://github.com/fastify/fastify-swagger I am using this internally (not that this issue might not be related to arktype I just noticed the difference when I was migrating and it's a pretty big deal)
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
where with zod its correct 0 or 1
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
it's just 0
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
then u can see that value is not an enum
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
No description
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
But when u actually paste it to open api
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
that's this params
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
export const S_params = type({
v: "'0' | '1'"
})
export const S_params = type({
v: "'0' | '1'"
})
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
openapi: 3.0.3
info:
title: Docs
version: 1.0.0
components:
schemas: {}
paths:
/v{v}/route:
get:
parameters:
- schema:
anyOf:
- enum:
- '0'
- enum:
- '1'
in: path
name: v
required: true
responses:
'200':
description: Default Response
openapi: 3.0.3
info:
title: Docs
version: 1.0.0
components:
schemas: {}
paths:
/v{v}/route:
get:
parameters:
- schema:
anyOf:
- enum:
- '0'
- enum:
- '1'
in: path
name: v
required: true
responses:
'200':
description: Default Response
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
The difference is the interpretation of such a schema by open api generators
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
and ArkType has anyOf
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
This is the generated JSON for both. You can see that zod has
myUnion: {
type: [ "number", "boolean" ],
}
myUnion: {
type: [ "number", "boolean" ],
}
32 replies
Aarktype
Created by stanisław on 2/27/2025 in #questions
ArkType `toJsonSchema` returning not open-api compatible schema.
ZOD {
$ref: "#/definitions/mySchema",
definitions: {
mySchema: {
type: "object",
properties: {
myString: {
type: "string",
minLength: 5,
},
myUnion: {
type: [ "number", "boolean" ],
},
},
required: [ "myString", "myUnion" ],
additionalProperties: false,
description: "My neat object schema",
},
},
$schema: "http://json-schema.org/draft-07/schema#",
}
ARKTYPE {
type: "object",
properties: {
myString: {
type: "string",
minLength: 5,
},
myUnion: {
anyOf: [
{
type: "number",
}, {
type: "boolean",
}
],
},
},
required: [ "myString", "myUnion" ],
}
ZOD {
$ref: "#/definitions/mySchema",
definitions: {
mySchema: {
type: "object",
properties: {
myString: {
type: "string",
minLength: 5,
},
myUnion: {
type: [ "number", "boolean" ],
},
},
required: [ "myString", "myUnion" ],
additionalProperties: false,
description: "My neat object schema",
},
},
$schema: "http://json-schema.org/draft-07/schema#",
}
ARKTYPE {
type: "object",
properties: {
myString: {
type: "string",
minLength: 5,
},
myUnion: {
anyOf: [
{
type: "number",
}, {
type: "boolean",
}
],
},
},
required: [ "myString", "myUnion" ],
}
32 replies