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] Extend openapi client generation #620

Open
2 tasks done
langehm opened this issue Dec 4, 2024 · 1 comment
Open
2 tasks done

[Feature] Extend openapi client generation #620

langehm opened this issue Dec 4, 2024 · 1 comment
Labels
Priority: Low The issue contains work with low priority. Template: Frontend Issues regarding the frontend template. Template: Webcomponent Issues regarding the webcomponent template. Type: Feature The issue is an feature

Comments

@langehm
Copy link
Contributor

langehm commented Dec 4, 2024

Relevant template

No response

Problem description (optional)

After closing this issue the api will be generated automatically.
But using it in the client still leaves some room for improvement. Futhermore there exists not generator for vue.

Desired solution

Generate some api function with vue functionality (reactivity - see example below).
This example exposes reactive variables to the component which simplifies the implementation a lot in VueJS.
The below code can be used to manually create those function for each api call - this is probably doable for a few request but not if this needs to be done for the whole specification.

Example for some generic vue implementation for calling the api:

export function useApiCall<TRequest, TResponse = void>(
  apiMethod: (params: TRequest) => Promise<TResponse>
) {
  const loadingInternal = ref(false);
  const errorInternal = ref(false);
  const dataInternal = ref<TResponse | null>(null);

  const loading = readonly(loadingInternal);
  const error = readonly(errorInternal);
  const data = readonly(dataInternal);

  const call = (params: TRequest): Promise<TResponse | boolean> => {
    loadingInternal.value = true;
    errorInternal.value = false;

    return apiMethod(params)
      .then((data) => (dataInternal.value = data))
      .catch(() => (errorInternal.value = true))
      .finally(() => (loadingInternal.value = false));
  };

  return {
    loading,
    error,
    data,
    call,
  };
}

Considered alternatives (optional)

Alternative soultion would be to customize the openapi generator. This can be done with the provided .mustache files (example for the DefaultApi).
Now there exist two ways to do this:

  1. use the templating mechanism to inject a custom template upon generating the files
  2. donate a contribution to the openapi-generator project with implementing a generator type for typescript-vue

Additional context (optional)

No response

No duplicate

  • I confirm that this issue is not a duplicate

Code of Conduct

  • I agree to follow this project's Code of Conduct
@langehm
Copy link
Contributor Author

langehm commented Dec 4, 2024

This issue depends on the previous openapi issue #619

@devtobi devtobi added Template: Webcomponent Issues regarding the webcomponent template. Template: Frontend Issues regarding the frontend template. Priority: Low The issue contains work with low priority. labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Low The issue contains work with low priority. Template: Frontend Issues regarding the frontend template. Template: Webcomponent Issues regarding the webcomponent template. Type: Feature The issue is an feature
Projects
Development

No branches or pull requests

2 participants