OpenAPITools / OpenAPITools/openapi-generator

[BUG][TYPESCRIPT-AXIOS] the content must be served over HTTPS

Open
#4,456 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

I got the following error when trying to access the api from my react-app:

Mixed Content: The page at 'https://example.com/#/dashboard/analytics' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.example.com:443/foo'. This request has been blocked; the content must be served over HTTPS.

I can see that the generated Code looks like this

export const BASE_PATH = "http://api.example.com:443".replace(/\/+$/, "");

while the host-property in the swagger.json looks like this:

{
	"swagger": "2.0",
	"info": {
		"description": "Api Documentation",
		"version": "1.0",
		"title": "Api Documentation",
		"termsOfService": "urn:tos",
		"contact": {},
		"license": {
			"name": "Apache 2.0",
			"url": "http://www.apache.org/licenses/LICENSE-2.0"
		}
	},
	"host": "api.example.com:443",
	"basePath": "/",
	"tags": [ ... ]
	...
}
openapi-generator version

4.1.2

Command line used for generation
openapi-generator generate --input-spec swagger.json --generator-name typescript-axios --output gen/api --config api.json

```json
{
	"npmName": "typescript-fetch-api",
	"npmVersion": "1.0.0",
	"snapshot" : false,
	"supportsES6": false,
	"modelPropertyNaming": "original"
}
Suggest a fix

I think that in the swagger.json the notation of :443 is important that the generator would know that it should be served as https. But then it would make more sense to actually use https then in the BASE_PATH constant. Otherwise Chrome and maybe other Browsers wont allow a connection to this endpoint from a https resource.

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 typescript-axios generation with the provided swagger.json, command, and api.json, then inspect where the generated BASE_PATH is assembled. Confirm how the swagger.json host value is interpreted and verify that generation produces an HTTPS endpoint for the HTTPS API without breaking other schemes.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.