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

Parameter query is not converted to correct type #554

Open
davidnewcomb opened this issue Apr 17, 2023 · 1 comment · May be fixed by #571
Open

Parameter query is not converted to correct type #554

davidnewcomb opened this issue Apr 17, 2023 · 1 comment · May be fixed by #571

Comments

@davidnewcomb
Copy link

I have a definition:

      parameters:
      - name: from
        in: query
        description: Which page to get
        required: false
        schema:
          type: integer
          format: int64

But when it hits my handler e.g.:

export async function newslist(c, req, res) {
    console.log('newslist:c.request.query: ' + JSON.stringify(c.request.query))

it becomes:

newslist:c.request.query: {"from":"123"}

instead of:

newslist:c.request.query: {"from":123}

So I have to do all the type converting which I would have thought openapi-backend would do for me.

On a similar note, I included the ajv-formats to use date-time string format and was expecting to get a native Javascript Date but I don't, I just get a string that's been parsed for correctness.

I think openapi-backend should do these kinds of conversions but if it can't, do you have an easy way for me to add type converters?

@sabeslamidze sabeslamidze linked a pull request May 12, 2023 that will close this issue
@ydayagi
Copy link

ydayagi commented Dec 5, 2023

@davidnewcomb
I have a similar issue.

namespace Parameters {
            export type ContainsText = string;
            export type CreatedAfter = string; // date-time
            export type MessageScope = "all" | "user" | "system";
            export type OrderBy = "title" | "message" | "created" | "topic" | "origin";
            export type OrderByDirec = "asc" | "desc";
            export type PageNumber = number;
            export type PageSize = number;
            export type Read = boolean;
            export type User = string;
        }
        export interface QueryParameters {
            pageSize?: Parameters.PageSize;
            pageNumber?: Parameters.PageNumber;
            orderBy?: Parameters.OrderBy;
            orderByDirec?: Parameters.OrderByDirec;
            containsText?: Parameters.ContainsText;
            createdAfter?: Parameters.CreatedAfter /* date-time */;
            messageScope?: Parameters.MessageScope;
            user?: Parameters.User;
            read?: Parameters.Read;
        }
        namespace Responses {
            export type $200 = Components.Schemas.Notifications;
        }
        }```
The number fields, such as pageSize, are in runtime of type string.

@davidnewcomb how did u enable 'date-time'

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

Successfully merging a pull request may close this issue.

2 participants