© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
Kitty

❔ Swagger does not generate schemas

    [HttpGet]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
    public async Task<IActionResult> Get(double latitude, double longitude)
    {
        // Create a HttpClient instance
        var client = _clientFactory.CreateClient();

        // Make a GET request to the external API
        var response = await client.GetAsync($"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current_weather=true");

        // If the request is successful
        if (response.IsSuccessStatusCode)
        {
            // Read the response content as a JSON string
            var json = await response.Content.ReadAsStringAsync();

            // Deserialize the JSON string into a WeatherForecastClass object
            var weatherForecast = JsonSerializer.Deserialize<WeatherForecastClass>(json);

            // Return the weather forecast with a 200 OK status
            return Ok(weatherForecast);
        }

        // If the request is not successful, log an error and return the status code from the external API
        _logger.LogError("Failed to retrieve weather forecast. Status Code: {ResponseStatusCode}", response.StatusCode);
        return StatusCode((int)response.StatusCode);
    }
}
    [HttpGet]
    [ProducesResponseType(StatusCodes.Status200OK)]
    [ProducesResponseType(StatusCodes.Status500InternalServerError)]
    public async Task<IActionResult> Get(double latitude, double longitude)
    {
        // Create a HttpClient instance
        var client = _clientFactory.CreateClient();

        // Make a GET request to the external API
        var response = await client.GetAsync($"https://api.open-meteo.com/v1/forecast?latitude={latitude}&longitude={longitude}&current_weather=true");

        // If the request is successful
        if (response.IsSuccessStatusCode)
        {
            // Read the response content as a JSON string
            var json = await response.Content.ReadAsStringAsync();

            // Deserialize the JSON string into a WeatherForecastClass object
            var weatherForecast = JsonSerializer.Deserialize<WeatherForecastClass>(json);

            // Return the weather forecast with a 200 OK status
            return Ok(weatherForecast);
        }

        // If the request is not successful, log an error and return the status code from the external API
        _logger.LogError("Failed to retrieve weather forecast. Status Code: {ResponseStatusCode}", response.StatusCode);
        return StatusCode((int)response.StatusCode);
    }
}

Swagger does not generate schema for WeatherForecastClass
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Swagger shows unwanted schemas when with minimal api
C#CC# / help
3y ago
.resx does not properly generate Design-File
C#CC# / help
2y ago
Does structs generate inaccessible copies?
C#CC# / help
2y ago