-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: support additional properties without xDictionaryKey #52
fix: support additional properties without xDictionaryKey #52
Conversation
if (additionalProperties.items && additionalProperties.items[SwaggerProps.$ref]) { | ||
res = `${parseRefType(additionalProperties.items[SwaggerProps.$ref].split('/'))}[]`; | ||
} else { | ||
res = `"// TODO: Something is wrong"`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wouldnt recommend to put TODOs in code even if its for logging purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, but in this PR I focused on adding the support for additional properties type without dictionnary, without changing existing patterns. - This part of the code is in fact duplicated from the one that handle the additionalProperties that have dictionnary ref.
I have upcoming PRs to improve on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But at the end of the day, we will still want to write in the result file.
Something more like this ?
// Error: DataTypes.Array without items or items ref is not supported
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! Its more helpful
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@nemrosim can you check as well, as you are the most familiar with this repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, few comments
tests/getDescription.test.ts
Outdated
describe(`getDescription`, () => { | ||
scenarios.forEach(config => { | ||
it(`should return ${config.expected} when props is ${config.props}`, async () => { | ||
const result = getDescription(config.props); | ||
|
||
expect(result).toBe(config.expected); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use it.each
instead of scenarios
. And why test is async
?
it.each([['case 1',{input: output}],['case 2', {input, output}]])('%s ....', (_, props) => <do something>);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
describe(`getResultStringForAdditionalPropertiesType`, () => { | ||
scenarios.forEach(config => { | ||
it(`should return expected result when props is ${config.scenarioName}`, async () => { | ||
const result = getResultStringForAdditionalPropertiesType(config.props); | ||
|
||
expect(result).toBe(config.expected); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, async not needed too, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
description, | ||
propertyName, | ||
}: { | ||
additionalProperties: any; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why any
? I see that you are testing additionalProperties
with known props. (I understand that probably there could be some changes in the future, but at least we can define known props at the moment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
additionalProperties
is returned by getSchemaProperties
, which type it as additionalProperties: any
We don't have any type guard or logic in typesConverter
to known the types of additionalProperties
by the time we pass it to getResultStringForAdditionalPropertiesType
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
of course, that could be improve, but in this PR I wanted to have a minimal number of change, just introducing the new helpers needed to resolve the issue I add with the samples marketplace types.
* fix: move helpers in individual files, improve typing * fix: replace 4 space by a tab characters, update unit test * fix: helpers for undefined type, ref and oneOf * fix: typing * fix: remove change that impact snapshot or expected result of unit test * fix: adjust props * fix: adding coverage (#54) * fix: add coverage * fix: update coverage * fix: improve error message * fix: improve error message * fix: convert space into tab charaters and use return character * fix: commit yarn.lock * fix: update test * fix: remove describe, remove test name
* fix: generate mock for additional properties without dictionnary * fix: update error message * fix: update mock generator and coverage
SamplesMarketplace swagger have this value :
https://api3-dev.landr.com/samplesmarketplace/swagger/v1/swagger.json#/
that got type as is :
where I was expecting this :
I found that we were not properly handling value with
additionalProperties
but without axDictionaryKey
.Part 1 - This PR
Part 2 - #53
Part 3 - #54