swagger-api / swagger-api/swagger-codegen

[NancyFx] response of type 'file' not supported

Open
#7,547 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

If a swagger specification defines a response of type file,
then the generated nancy server stub produces code that compiles but that fails at runtime (see below).

Swagger-codegen version

Current master (2.3.1+)

Swagger declaration file content or url

If you post the code inline, please wrap it with

swagger: "2.0"
info:
  version: "1.0.0"
  title: Demo

paths:
  /foo:
    get:
      summary: retrieve a file
      responses:
        200:
          description: success
          schema:
            type: file
Command line used for generation

generate -i C:\temp\file_response\swagger.yaml -o C:/temp/file_response/nancy/ -l nancyfx --additional-properties packageContext=v1,interfacePrefix=I

Related issues/PRs

Not that I'm aware of.

Suggest a fix/enhancement

The swagger spec from above generates the following Nancy Module:

public sealed class DefaultModule : NancyModule
    {
        /// <summary>
        /// Sets up HTTP methods mappings.
        /// </summary>
        /// <param name="service">Service handling requests</param>
        public DefaultModule(IDefaultService service) : base("")
        { 
            Get["/foo"] = parameters =>
            {
                
                return service.FooGet(Context);
            };
        }
    }

This code does not compile as service.FooGet will return a System.IO.Stream that is not accepted by nancy. I suggest to change the signature of the FooGet method from

System.IO.Stream FooGet(NancyContext context)

to

Nancy.Response FooGet(NancyContext context)

. In this way, the implementor of the service can return the file using e.g. a Nancy.StreamResponse or a Nancy.GenericFileResponse.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the supplied Swagger YAML and NancyFX generation command, then inspect the generated DefaultModule and FooGet service signature shown in the report. Verify the generated response handling against Nancy's expected response types; done means a file response can be implemented and returned without the generated server failing at runtime.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.