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

Feature Request: create factory method for instantiating OpenAPI models #1331

Open
mironbalcerzak opened this issue Apr 26, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@mironbalcerzak
Copy link
Contributor

mironbalcerzak commented Apr 26, 2024

What are the steps to reproduce this issue?

Using any schema, do generate models, we get following (example):

export interface User {
  name: string;
  age: number;
  address: Address;
}

export interface Address {
  street: string;
  city: string;
}

What were you expecting to happen?

Beside interface, getting a factory method (naive approach)

export function createUser() {
  return {
    name: '',
    age: 0,
    address: createAddress(),
  };
}

export function createAddress() {
  return {
    street: '',
    city: '',
  };
}

Naturally, all primitive types should be handled, re complex (other schema types) - we should discuss on how to handle "relationship"

Motivation

Initializing state in react components is very tedious work

What versions are you using?

Package Version: 6.27.1

@anymaniax
Copy link
Owner

Could be another possibility for the mocking maybe?

@mironbalcerzak
Copy link
Contributor Author

mironbalcerzak commented Apr 28, 2024

@anymaniax uhm - mocking with the schema that i use is throwing an error... so i am not sure what "mocking" exactly does :) (will debug and fix soon-ish).

as per what i understand, "mocks" are generated against service layer though..

This one is meant to be used as a convenient way of creating ready-to-go objects (-> useState(createAddress());

@mironbalcerzak mironbalcerzak removed their assignment Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants