Skip to content
This repository was archived by the owner on Nov 11, 2023. It is now read-only.
This repository was archived by the owner on Nov 11, 2023. It is now read-only.

Generating a client with path params containing dots '.' fails #377

@willycoll

Description

@willycoll

Describe the bug
clients generated from swagger.json with path parameters containing dots . contain errors

To Reproduce
Steps to reproduce the behavior:

{
  "swagger": "2.0",
  "info": {
    "title": "contiamo/restful-react bug",
    "version": "0.0.0"
  },
  "consumes": [
    "application/json"
  ],
  "produces": [
    "application/json"
  ],
  "paths": {
    "/foo/{bar.baz}": {
      "get": {
        "operationId": "foo",
        "responses": {
          "200": {
            "description": "A successful response."
          },
          "default": {
            "description": "An unexpected error response."
          }
        },
        "parameters": [
          {
            "name": "bar.baz",
            "in": "query",
            "required": false,
            "type": "string"
          }
        ]
      }
    }
  }
}
  1. restful-react import --file swagger.json --output client.tsx
  2. That generates the following invalid tsx:
/* Generated by restful-react */

import React from "react";
import { Get, GetProps, useGet, UseGetProps } from "restful-react";
export const SPEC_VERSION = "0.0.0"; 

export interface FooQueryParams {
  "bar.baz"?: string;
}

export type FooProps = Omit<GetProps<void, void, FooQueryParams, void>, "path">;

export const Foo = (props: FooProps) => (
  <Get<void, void, FooQueryParams, void>
    path={`/foo/${bar.baz}`}
    
    {...props}
  />
);

export type UseFooProps = Omit<UseGetProps<void, void, FooQueryParams, void>, "path">;

export const useFoo = (props: UseFooProps) => useGet<void, void, FooQueryParams, void>(`/foo/${bar.baz}`, props);

Expected behavior
A valid client.tsx file

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS Big Sur 11.5.2
  • Browser: Firefox
  • Version 92.0.1

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions