swagger-api / swagger-api/swagger-codegen

[typescript-fetch] fails on BOM

Open
#7,856 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

typescript-fetch codegen is failing on BOM (0xfeff in error below)

[main] ERROR io.swagger.parser.SwaggerCompatConverter - failed to read resource listing
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('?' (code 65279 / 0xfeff)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
 at [Source: java.io.StringReader@3570b7; line: 1, column: 2]
	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1702)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:558)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportUnexpectedChar(ParserMinimalBase.java:456)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._handleOddValue(ReaderBasedJsonParser.java:1906)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:749)
	at com.fasterxml.jackson.databind.ObjectMapper._initForReading(ObjectMapper.java:3850)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:3799)
	at com.fasterxml.jackson.databind.ObjectMapper.readTree(ObjectMapper.java:2397)
	at io.swagger.parser.SwaggerCompatConverter.readResourceListing(SwaggerCompatConverter.java:187)
	at io.swagger.parser.SwaggerCompatConverter.read(SwaggerCompatConverter.java:116)
	at io.swagger.parser.SwaggerParser.read(SwaggerParser.java:75)
	at io.swagger.codegen.config.CodegenConfigurator.toClientOptInput(CodegenConfigurator.java:431)
	at io.swagger.codegen.cmd.Generate.run(Generate.java:283)
	at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Exception in thread "main" java.lang.RuntimeException: missing swagger input or config!
	at io.swagger.codegen.DefaultGenerator.generate(DefaultGenerator.java:731)
	at io.swagger.codegen.cmd.Generate.run(Generate.java:285)
	at io.swagger.codegen.SwaggerCodegen.main(SwaggerCodegen.java:35)
Swagger-codegen version

2.3.1

Swagger declaration file content or url

repros with any otherwise valid swagger content returned by server using BOM

Command line used for generation

call command:
java -jar <path/to/swagger-codegen> generate -i <path/to/swaggerJson> -l typescript-fetch -t <path/to/templates> -c <path/to/config> -o <path/to/desired/output>

which we trigger from npm script that actually defines all those paths:

const execSync = require('child_process').execSync;
// code that generates paths and assigns above command to var execString
execSync(execString, { stdio: ['ignore', 'ignore', stdErr] });

config:

{
    "allowUnicodeIdentifiers" : false,
    "ensureUniqueParams": true,
    "modelPropertyNaming": "camelCase",
    "sortParamsByRequiredFlag": true,
    "supportsES6" : false
}
Steps to reproduce

repros every time on using a swagger.json returned by a server that sends BOM

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/6971, https://github.com/swagger-api/swagger-codegen/issues/3680

Suggest a fix/enhancement

manually stripping BOM from the file will resolve the issue. since swagger-codegen already supports pulling the file from upstream/URL, I would prefer to have swagger-codegen do this BOM removal. otherwise, consumers will have to curl the upstream file themselves, strip BOM, and then call swagger-codegen. in that case, doesn't seem like codegen needs to support curl upstream. :(

something like this could be used / forked and rewritten for java/swagger:

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure with a Swagger JSON response prefixed by a BOM and trace the input path through SwaggerCodegen and the parser stack shown in the error. The fix is complete when the existing command succeeds against a BOM-prefixed URL without requiring consumers to preprocess the file.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.