Skip to content
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

Option to use the JSON property names as the member names #1021

Open
schani opened this issue Aug 9, 2018 · 1 comment
Open

Option to use the JSON property names as the member names #1021

schani opened this issue Aug 9, 2018 · 1 comment

Comments

@schani
Copy link
Member

@schani schani commented Aug 9, 2018

A lot of people are requesting this, with a variety of different slightly weird reasons.

@hi2u
Copy link

@hi2u hi2u commented Oct 29, 2020

@schani Is there still no way to disable the automatic renaming of properties at all? Or am I missing something?

I've spent many hours looking into this, and there's heaps of other issues asking for it... is there at least some dodgy hack I can do to disable the renaming of properties?

Right now I'm:

  • Using quicktype-core in my Node app
  • passing in sample JSON files
  • outputting Rust structs

Here's my code so far:

const jsonInput = jsonInputForTargetLanguage('rust');
await jsonInput.addSource({
    name: 'MainStructName',
    samples: json_samples,
});

const inputData = new InputData();
inputData.addInput(jsonInput);

const result = await quicktype({
    inputData,
    lang: 'rust',
    inferDateTimes: false,
    alphabetizeProperties: true,
    inferEnums: false,
    rendererOptions: {},
});

Although I'm keen to figure this out for any output language, not just Rust.

Looking through some of the source code, I can see stuff such as:

protected namerForObjectProperty(): Namer | null;

...the | null implies it can be disabled? And the fact that it's a property implies that these are pluggable and maybe I can supply my own naming function?

But I can't figure out how to actually do it.

Is it possible at all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.