Comments (13)
Thank you for your help, I simplified my custom-instance and used interceptors properly and it is solved, so I appreciate the exchange.
from orval.
I just tried it with 6.20.0 and can't reproduce. Headers False does not create headers but headers:true does. Please provide and exact reproducer.
from orval.
It is in propriety code and a large api. Can you share your config to produce no headers? Is mine in the right place?
I will try to spin it up connecting to placeholder api.
from orval.
Sure it looks like this..
module.exports = {
myservice: {
output: {
target: "src/service/MyService.ts",
client: "react-query",
mock: false,
prettier: false,
headers: true,
override: {
useDates: false,
mutator: {
path: "src/service/AxiosMutator.ts",
name: "useAxiosMutator",
},
query: {
useQuery: true,
},
},
},
input: {
target: "./openapi.json",
},
},
};
And my JSON looks like this for OpenAPI.
"paths": {
"/domino/dataset/file/content/{snapshotId}": {
"get": {
"tags": ["Domino"],
"summary": "Get a single file content",
"description": "Gets the contents of a single file as a string.",
"parameters": [
{
"name": "X-Domino-Api-Key",
"in": "header",
"description": "Domino API Key",
"required": true,
"schema": {
"type": "string"
},
"example": "83b8568486a99e4a61a49583fd8bea78cbe51ccfbabed01fa04bedf9c875ff96"
},
{
"name": "X-Domino-Api-Url",
"in": "header",
"description": "Domino URL",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "snapshotId",
"in": "path",
"description": "Snapshot Identifier",
"required": true,
"schema": {
"type": "string"
}
},
{
"name": "filePath",
"in": "query",
"description": "File Path",
"required": true,
"schema": {
"type": "string"
}
}
],
"responses": {
"200": {
"description": "File Content",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
},
"403": {
"description": "Forbidden",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiError"
}
}
}
},
"500": {
"description": "Unexpected error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/ApiError"
}
}
}
}
}
}
},
from orval.
Thank you for sharing config-just wanted to make sure I had mine in the right place.
Here is a minimum repo
https://github.com/cheryl-c-tirerack/orval-debug
See
api/partners/post.ts
The createPartner is giving a header that conflicts with other type definitions. My backend says that is not coming from the json, shown in repo above.
Thanks for your time.
from orval.
Ohhh yours are Response
output headers not Request
input headers. That is what that property currently controls. Let me look.
from orval.
Wait these are the Content-Type headers to tell the server you want application-json? Why do you want those excluded?
It should always generate headers: { "Content-Type": "application/json" }
because your openAPI says
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Partner"
}
}
}
},
}
from orval.
I have headers set in my custom-instance, not shown in the reproduction.
If headers are set in my custom-instance has several, but the generated code does not show all of them, I get an eslint fail on build. It would be easier if all headers were controlled by my axios settings.
from orval.
Then I need a better example because that example above is working as expected? And can't you just override the headers with an Axios Mutator?
from orval.
I've updated the example with my full custom-instance.
The headers here do not match the headers in the generated code and so I get eslint / typescript errors on build.
I have struggled a bit to understand this version of the axios instance vs interceptors and other methods I see online. So this could be a failure of understanding on my part. Everything worked perfectly until I hit an api endpoint that generates those for me.
from orval.
oh I have always used Interceptors to inject headers.
import { AxiosInstance } from "axios";
/**
* Axios utlity class for adding token handling and Date handling to all request/responses.
*/
export default class AxiosInterceptors {
// hold instances of interceptor by their unique URL
static requestInterceptors = new Map<string, number>();
static responseInterceptors = new Map<string, number>();
/**
* Configures Axios request/reponse interceptors to add JWT token.
*
* @param {AxiosInstance} instance the Axios instance to remove interceptors
* @param {string} apiKey the API Key to add to all Axios requests
* @param {string} apiUrl the API URL to add to all Axios requests
*/
static setupAxiosInstance = (instance: AxiosInstance, apiKey: string, apiUrl: string) => {
const appKey = instance.defaults.baseURL!;
EnvUtils.debug(`Configuring Axios request/response interceptors for: ${apiKey}`);
// Axios request interceptor to add JWT token
const tokenRequestInterceptor = instance.interceptors.request.use(
(config) => {
if (apiKey) {
const headers = config.headers || {};
headers["X-Domino-Api-Key"] = apiKey;
headers["X-Domino-Api-Url"] = apiUrl;
}
return config;
},
(error) => {
return Promise.reject(error);
},
);
EnvUtils.debug(`Axios Token Request Interceptor: ${tokenRequestInterceptor}`);
AxiosInterceptors.requestInterceptors.set(appKey, tokenRequestInterceptor);
};
/**
* Cleanup Axios on sign out of application.
*
* @param {AxiosInstance} instance the Axios instance to remove interceptors
*/
static teardownAxiosInstance = (instance: AxiosInstance) => {
const appKey = instance.defaults.baseURL!;
EnvUtils.warn(`Cleaning up Axios removing all interceptors for: ${appKey}`);
instance.interceptors.request.clear();
instance.interceptors.response.clear();
};
}
Then use it like this setting it up once.
AxiosInterceptors.setupAxiosInstance(AXIOS_INSTANCE, dominoApiKey, dominoApiInstance);
from orval.
Going to close this for now as not an Orval issue
from orval.
No problem!
from orval.
Related Issues (20)
- Use better regex for route parameters
- Cannot generate strictly suspense query hooks HOT 3
- Input filters doesn't filter schemas
- allOf adds an unnecessary empty object in MSW file, resulting in broken syntax HOT 2
- Array schema values aren't marked as readonly HOT 2
- Duplicate function name in msw when route depth is one, e.g. /NotWorking HOT 2
- Type alias exports missing when using cross-file $ref HOT 2
- OpenAPI 3.1: Generator seems to not support `const` field in schema HOT 2
- Orval does not respect the "optional by default" `requestBody` for OpenAPI 3.0
- 6.23.0 adds blank values to required enums HOT 1
- Syntax error in mock function when allOf and nested schema references are used together HOT 1
- Different return types depending on status code alone HOT 2
- Updating from 6.19.1 to 6.20.0 leads to TypeError: Cannot read properties of undefined (reading 'length') HOT 4
- Upgrading `prettier` to `v3` causes an error in `pretty-quick` HOT 7
- Add support for Jotai Tanstack Query
- `init?: RequestInit` should be exposed in generated API functions when using fetch customInstance. HOT 3
- feature: log which version of rect-query is detected
- Makes the decision process for importing dependencies stricter HOT 1
- Sample: axios cancelToken is deprecated HOT 1
- Generate true Typescript enums HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from orval.