question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is there a way to add a custom apiTemplateFile if queryParams are present? [dart-dio-next]

See original GitHub issue
Description

I am trying to add an additional apiTemplateFile when some queryParams are present for the api.

For example, in the case of petstore.yaml, this is what I want to do:

lib
    - src
        - api
            - pet_api.dart
            - pet_api_query.dart      // <----- New file
            - store_api.dart
            - user_api.dart        
            - user_api_query.dart     // <----- New file
        - model
            - api_response.dart
            - category.dart
            - date.dart
            - order.dart
            - pet.dart
            - tag.dart
            - user.dart
        - api.dart
        - serailizers.dart
    openapi.dart

I intend to place some Built classes like this in the *_query.dart (ideally in a different folder than api), but only for operations that contain at least one query parameter.

abstract class FindPetsByStatusQuery implements Built<FindPetsByStatusQuery, FindPetsByStatusQueryBuilder> {

    FindPetsByStatusQuery._();

    factory FindPetsByStatusQuery([void Function(FindPetsByStatusQueryBuilder) updates]) = _$FindPetsByStatusQuery;

    String? get status;

}
What I have tried so far
  • I have tried adding in a conditional statement inside the fromOperation method, but it still does not behave any differently. Am I looking/editing in the wrong place?
  • I also have a feeling that I should create a supporting file. But again I could not find any documentation on how to create a supporting file for every operation that contains a queryParam.

Any help would be appreciated.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kuhnroyalcommented, Aug 13, 2021

I see, but you won’t make it work with supporting files either. Those are meant to be used for single files like util classes etc. - you can not pass the operation. They always receive the full context.

You can try overriding generateApis, first call super, then filter out all operations with query parameters and basically repeat the block I linked above but only with the operations that you filtered.

1reaction
kuhnroyalcommented, Jul 16, 2021

You may be interested in the latest discussions here: https://github.com/OpenAPITools/openapi-generator/issues/6582 if you want to chip in there, you may be able to avoid having to roll your custom solution.

In the meantime, as you have noted, you have to add a supporting file somewhere in configureSerializationLibraryBuiltValue. Inside this template you iterate over {{#operations}} and figure out which one need which query generated. As I have noted in #6582 it may be useful to also generate extensions on the API classes that accept these query classes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - How can I add or update a query string parameter?
I wrote the following function which accomplishes what I want to achieve: function updateQueryStringParameter(uri, key, value) { var re = new RegExp("([?
Read more >
Using query parameters to create a pull request - GitHub Docs
Use query parameters to create custom URLs to open pull requests with pre-populated fields.
Read more >
Use query parameters to customize responses - Microsoft Graph
Microsoft Graph provides optional query parameters that you can use to specify and control the amount of data returned in a response.
Read more >
URLSearchParams - Web APIs - MDN Web Docs
Chrome Edge URLSearchParams Full support. Chrome49. Toggle history Full support. Edge... @@iterator Full support. Chrome49. Toggle history Full support. Edge... URLSearchParams() constructor Full support. Chrome49. Toggle...
Read more >
Parameters - Looker Studio Help - Google Help
Calculated field with parameter example · Edit or create a report. · If necessary, add your data source to the report. · At...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found