Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
41ea9df to
d17034d
Compare
| if len(inputs) == 0 { | ||
| fmt.Fprintln(cmd.OutOrStdout(), "[]") | ||
| return nil | ||
| } | ||
|
|
||
| // Convert to retriever.RetrievedSchema with inline source type | ||
| schemas := make([]retriever.RetrievedSchema, len(inputs)) | ||
| for i, in := range inputs { |
There was a problem hiding this comment.
Missing SourceURI breaks refs
retriever.RetrievedSchema.SourceURI is used as the base URI for resolving relative $ref values and for bundler error context/caching. In convert, schemas are constructed without SourceURI, so any schema containing relative refs (or circular refs that rely on cache seeding) can fail or resolve incorrectly. Consider setting a stable synthetic URI per input (e.g. inline://<namespace>/<id>), or accept sourceURI in ConvertSchemaInput and plumb it through.
Prompt To Fix With AI
This is a comment left during a code review.
Path: cli/cmd/convert.go
Line: 90:97
Comment:
**Missing SourceURI breaks refs**
`retriever.RetrievedSchema.SourceURI` is used as the base URI for resolving relative `$ref` values and for bundler error context/caching. In `convert`, schemas are constructed without `SourceURI`, so any schema containing relative refs (or circular refs that rely on cache seeding) can fail or resolve incorrectly. Consider setting a stable synthetic URI per input (e.g. `inline://<namespace>/<id>`), or accept `sourceURI` in `ConvertSchemaInput` and plumb it through.
How can I resolve this? If you propose a fix, please make it concise.| ``` | ||
| </Tab> | ||
| <Tab value="poetry"> | ||
| ```bash | ||
| poetry add xschema-runtime | ||
| ``` | ||
| </Tab> | ||
| </Tabs> | ||
|
|
There was a problem hiding this comment.
Python API mismatch
This planned Python snippet calls convert(..., adapter="@xschemadev/zod"), but the TypeScript runtime you just introduced requires adapter: XSchemaAdapter (object with .id). If Python is intended to “mirror” the TS API, the docs should match one shape consistently; otherwise users will copy/paste an API that can’t exist alongside the current TS design.
Prompt To Fix With AI
This is a comment left during a code review.
Path: web/content/docs/runtime/getting-started/python.mdx
Line: 58:66
Comment:
**Python API mismatch**
This planned Python snippet calls `convert(..., adapter="@xschemadev/zod")`, but the TypeScript runtime you just introduced requires `adapter: XSchemaAdapter` (object with `.id`). If Python is intended to “mirror” the TS API, the docs should match one shape consistently; otherwise users will copy/paste an API that can’t exist alongside the current TS design.
How can I resolve this? If you propose a fix, please make it concise.| schemas: SchemaInput | SchemaInput[], | ||
| options: ConvertOptions, | ||
| ): Promise<ConvertResult[]> { | ||
| const input = Array.isArray(schemas) ? schemas : [schemas]; | ||
| const bin = options.executablePath ?? "xschema"; | ||
|
|
||
| const args = ["convert", "--adapter", options.adapter.id]; | ||
| if (options.allowFetch) args.push("--allow-fetch"); | ||
| if (options.cwd) args.push("--project", options.cwd); |
There was a problem hiding this comment.
Backpressure can hang
child.stdin.write(JSON.stringify(input)); child.stdin.end(); ignores backpressure and write errors. If write() returns false (large schema payloads) or emits an error, the subprocess may never receive the full input/EOF, and this promise can hang. Consider handling the write() return value (wait for drain) and listening for child.stdin.on("error", ...).
Prompt To Fix With AI
This is a comment left during a code review.
Path: typescript/packages/runtime/src/index.ts
Line: 30:38
Comment:
**Backpressure can hang**
`child.stdin.write(JSON.stringify(input)); child.stdin.end();` ignores backpressure and write errors. If `write()` returns `false` (large schema payloads) or emits an `error`, the subprocess may never receive the full input/EOF, and this promise can hang. Consider handling the `write()` return value (wait for `drain`) and listening for `child.stdin.on("error", ...)`.
How can I resolve this? If you propose a fix, please make it concise.
Greptile Overview
Greptile Summary
This PR adds a new “runtime” workflow that exposes the existing xschema pipeline via (1) a new Go CLI subcommand
xschema convertthat reads a JSON array of schema inputs from stdin and emits a JSON array of conversion results to stdout, and (2) a new TypeScript package@xschemadev/runtimethat spawns the CLI to provide a programmaticconvert()API.To support runtime selection, each TS adapter package now exports an
adaptermetadata object and core introduces anXSchemaAdaptertype. The web docs are updated with a runtime overview and API reference.Key issues to address before merging:
xschema convertconstructsretriever.RetrievedSchemavalues withoutSourceURI, but downstream processing/bundling usesSourceURIas the base for$refresolution and for cache seeding/error context; relative refs can break.@xschemadev/runtimewrites to the child stdin without handling backpressure or stdin errors; large payloads can hang.adapteras a string, which conflicts with the TypeScript runtime’sadapter: XSchemaAdapterobject shape and will mislead users.Confidence Score: 3/5
SourceURIinconvertbreaks relative $ref resolution in processor/bundler, and the runtime wrapper ignores stdin backpressure/error handling when sending JSON to the child process. Docs also currently diverge on adapter shape for the planned Python API.Important Files Changed
xschema convertcommand reading schema array from stdin and generating JSON results; missingRetrievedSchema.SourceURIwill break relative $ref resolution/bundling context.convertcommand; relies on built adapter CLI + bunx, but generally fine.@xschemadev/runtimepackage definition; exports dist entrypoints.convert()that spawnsxschema convert; missing stdin backpressure/error handling can hang on large payloads.XSchemaAdapterobject shape.Sequence Diagram
sequenceDiagram participant UserCode as User code (@xschemadev/runtime) participant Runtime as runtime.convert() participant XS as xschema CLI participant Proc as processor.Process participant Gen as generator.GenerateAll UserCode->>Runtime: convert(schemas, {adapter, cwd?, allowFetch?}) Runtime->>XS: spawn("xschema", ["convert","--adapter", adapter.id, ...]) Runtime->>XS: stdin.write(JSON.stringify(schemas)) XS->>Proc: Process(retrievedSchemas, {Fetcher, Cache, ...}) Proc->>Proc: crawlAndFetch external $ref (if allowed) Proc->>Proc: bundle schemas (uses SourceURI as base) XS->>Gen: GenerateAll(processed, lang, projectRoot) Gen-->>XS: []ConvertResult XS-->>Runtime: stdout (JSON) Runtime-->>UserCode: parsed ConvertResult[] XS-->>Runtime: stderr (errors/verbose)