Skip to content

Commit

Permalink
Fix moby OpenAPI generation
Browse files Browse the repository at this point in the history
The OpenAPI file now contains an example that is too large to fit into an
int64 but does fit in an uint64; however, our YAML parser unconditionally
parses it as an int64.  Work around the issue by manually doing a string
replacement on the file before passing it to the OpenAPI parser.

Signed-off-by: Mark Yen <[email protected]>
  • Loading branch information
mook-as committed Feb 20, 2025
1 parent 4fb2d0c commit ff4991e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions scripts/dependencies/moby-openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ export class MobyOpenAPISpec implements Dependency {

await download(url, outPath, { access: fs.constants.W_OK });

// As of 1.48 they have an example of an uint64 that's at 2^64-1 (i.e. max),
// but the YAML parser uses strconv.ParseInt() which only takes int64. This
// causes issues with `go generate`. Work around the issue by replacing the
// example string, which we don't care about anyway.
const originalContents = await fs.promises.readFile(outPath, 'utf-8');
const modifiedContents = originalContents.replace('example: 18446744073709551615', 'example: 9223372036854775807');

await fs.promises.writeFile(outPath, modifiedContents, 'utf-8');

await simpleSpawn('go', ['generate', '-x', 'pkg/dockerproxy/generate.go'], { cwd: path.join(process.cwd(), 'src', 'go', 'wsl-helper') });
console.log('Moby API swagger models generated.');
}
Expand Down

0 comments on commit ff4991e

Please sign in to comment.