This commit is contained in:
2026-10-15 17:33:06 +03:00
parent 62f5d0d3fa
commit a91bae98ac
36 changed files with 940 additions and 107 deletions
Binary file not shown.
@@ -1,46 +0,0 @@
using Scalar.AspNetCore;
// 1. Модели теперь можно объявить здесь, так как они находятся внутри пространства имен
public record Pokemon(int Id, string Name, string Type, int Level);
public record PokemonInput(string Name, string Type, int Level);
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();
var pokemons = new List<Pokemon>
{
new(1, "Pikachu", "Electric", 12),
new(2, "Charmander", "Fire", 8),
new(3, "Squirtle", "Water", 10)
};
// GET /pokemons
app.MapGet("/pokemons/{id}", (int id) =>
{
var pokemon = pokemons.FirstOrDefault(p => p.Id == id);
return pokemon is null
? Results.NotFound()
: Results.Ok(pokemon);
});
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapScalarApiReference(options =>
{
options.WithTitle("Pokedex API")
.WithOpenApiRoutePattern("/openapi/v1.json");
});
}
app.Run();
}
}
Binary file not shown.
@@ -0,0 +1,35 @@
info:
name: delete /pokemons/:id
type: http
seq: 5
tags:
- PokedexApi
http:
method: DELETE
url: http://localhost:5211/pokemons/6
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
examples:
- name: 200 Response
description: OK
request:
url: "{{baseUrl}}/pokemons/:id"
method: DELETE
params:
- name: id
value: ""
type: path
response:
status: 200
statusText: OK
body:
type: text
data: ""
@@ -0,0 +1,6 @@
info:
name: PokedexApi
type: folder
request:
auth: inherit
@@ -0,0 +1,35 @@
info:
name: get /pokemons/:id
type: http
seq: 3
tags:
- PokedexApi
http:
method: GET
url: http://localhost:5211/pokemons/5
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
examples:
- name: 200 Response
description: OK
request:
url: "{{baseUrl}}/pokemons/:id"
method: GET
params:
- name: id
value: ""
type: path
response:
status: 200
statusText: OK
body:
type: text
data: ""
@@ -0,0 +1,31 @@
info:
name: get /pokemons
type: http
seq: 2
tags:
- PokedexApi
http:
method: GET
url: http://localhost:5211/pokemons
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
examples:
- name: 200 Response
description: OK
request:
url: "{{baseUrl}}/pokemons"
method: GET
response:
status: 200
statusText: OK
body:
type: text
data: ""
@@ -0,0 +1,47 @@
info:
name: post /pokemons
type: http
seq: 3
tags:
- PokedexApi
http:
method: POST
url: http://localhost:5211/pokemons
body:
type: json
data: |-
{
"name": "Pikachu",
"type": "Electric",
"level": 12
}
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
examples:
- name: 200 Response
description: OK
request:
url: "{{baseUrl}}/pokemons"
method: POST
body:
type: json
data: |-
{
"name": "",
"type": "",
"level": ""
}
response:
status: 200
statusText: OK
body:
type: text
data: ""
@@ -0,0 +1,51 @@
info:
name: put /pokemons/:id
type: http
seq: 5
tags:
- PokedexApi
http:
method: PUT
url: http://localhost:5211/pokemons/1
body:
type: json
data: |-
{
"name": "Raichu",
"type": "Electric",
"level": 32
}
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
examples:
- name: 200 Response
description: OK
request:
url: "{{baseUrl}}/pokemons/:id"
method: PUT
params:
- name: id
value: ""
type: path
body:
type: json
data: |-
{
"name": "",
"type": "",
"level": ""
}
response:
status: 200
statusText: OK
body:
type: text
data: ""
@@ -0,0 +1,4 @@
name: Environment 1
variables:
- name: baseUrl
value: http://localhost:5211
@@ -0,0 +1,10 @@
opencollection: 1.0.0
info:
name: PokedexApi | v1 - 1
bundled: false
extensions:
bruno:
ignore:
- node_modules
- .git
@@ -0,0 +1,6 @@
info:
name: PokedexApi
type: folder
request:
auth: inherit
@@ -0,0 +1,34 @@
info:
name: get /hello
type: http
seq: 1
tags:
- PokedexApi
http:
method: GET
url: "{{baseUrl}}/hello"
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
examples:
- name: 200 Response
description: OK
request:
url: "{{baseUrl}}/hello"
method: GET
response:
status: 200
statusText: OK
headers:
- name: Content-Type
value: text/plain
body:
type: text
data: ""
@@ -0,0 +1,39 @@
info:
name: get /pokemons/:id
type: http
seq: 3
tags:
- PokedexApi
http:
method: GET
url: "{{baseUrl}}/pokemons/:id"
params:
- name: id
value: ""
type: path
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
examples:
- name: 200 Response
description: OK
request:
url: "{{baseUrl}}/pokemons/:id"
method: GET
params:
- name: id
value: ""
type: path
response:
status: 200
statusText: OK
body:
type: text
data: ""
@@ -0,0 +1,31 @@
info:
name: get /pokemons
type: http
seq: 2
tags:
- PokedexApi
http:
method: GET
url: "{{baseUrl}}/pokemons"
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
examples:
- name: 200 Response
description: OK
request:
url: "{{baseUrl}}/pokemons"
method: GET
response:
status: 200
statusText: OK
body:
type: text
data: ""
@@ -0,0 +1,4 @@
name: Environment 1
variables:
- name: baseUrl
value: http://localhost:5211
@@ -0,0 +1,34 @@
opencollection: 1.0.0
info:
name: PokedexApi | v1
version: "1"
config:
proxy:
inherit: true
config:
protocol: http
hostname: ""
port: ""
auth:
username: ""
password: ""
bypassProxy: ""
request:
variables:
- name: baseUrl
value: http://localhost:5211
bundled: false
extensions:
bruno:
ignore:
- node_modules
- .git
openapi:
- sourceUrl: ../../v1.json
groupBy: tags
lastSyncDate: 2026-10-15T12:42:49.890Z
specHash: 3772da9d0fb4ef0d1ddc6bccd9094f9d
autoCheck: true
autoCheckInterval: 5
@@ -1,6 +1,6 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokedexApi", "PokedexApi\PokedexApi.csproj", "{0AC1C38E-7B58-4271-9193-B74B674ECF6C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PokedexApi", "PokedexApi\PokedexApi.csproj", "{9A30BAE9-E0E9-413B-953F-26F43F01E17F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -8,9 +8,9 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0AC1C38E-7B58-4271-9193-B74B674ECF6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0AC1C38E-7B58-4271-9193-B74B674ECF6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0AC1C38E-7B58-4271-9193-B74B674ECF6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0AC1C38E-7B58-4271-9193-B74B674ECF6C}.Release|Any CPU.Build.0 = Release|Any CPU
{9A30BAE9-E0E9-413B-953F-26F43F01E17F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A30BAE9-E0E9-413B-953F-26F43F01E17F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A30BAE9-E0E9-413B-953F-26F43F01E17F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A30BAE9-E0E9-413B-953F-26F43F01E17F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
@@ -1,4 +1,4 @@
@PokedexApi_HostAddress = http://localhost:5116
@PokedexApi_HostAddress = http://localhost:5211
GET {{PokedexApi_HostAddress}}/weatherforecast/
Accept: application/json
@@ -0,0 +1,86 @@
using Scalar.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
app.MapScalarApiReference();
}
var pokemons = new List<Pokemon>
{
new(1, "Pikachu", "Electric", 12),
new(2, "Charmander", "Fire", 8),
new(3, "Squirtle", "Water", 10)
};
app.MapGet("/pokemons", () => Results.Ok(pokemons));
app.MapGet("/pokemons/{id}", (int id) =>
{
var pokemon = pokemons.FirstOrDefault(p => p.Id == id);
return pokemon is null ? Results.NotFound() : Results.Ok(pokemon);
});
app.MapPost("/pokemons", (PokemonInput input) =>
{
var errors = Validate(input);
if (errors.Count > 0)
{
return Results.BadRequest(new { errors });
}
var newId = pokemons.Count > 0 ? pokemons.Max(p => p.Id) + 1 : 1;
var pokemon = new Pokemon(newId, input.Name, input.Type, input.Level);
pokemons.Add(pokemon);
return Results.Created($"/pokemons/{newId}", pokemon);
});
app.MapPut("/pokemons/{id}", (int id, PokemonInput input) =>
{
var existing = pokemons.FirstOrDefault(p => p.Id == id);
if (existing is null)
{
return Results.NotFound();
}
var errors = Validate(input);
if (errors.Count > 0)
{
return Results.BadRequest(new { errors });
}
var updated = new Pokemon(id, input.Name, input.Type, input.Level);
pokemons[pokemons.IndexOf(existing)] = updated;
return Results.Ok(updated);
});
app.MapDelete("/pokemons/{id}", (int id) =>
{
var existing = pokemons.FirstOrDefault(p => p.Id == id);
if (existing is null)
{
return Results.NotFound();
}
pokemons.Remove(existing);
return Results.NoContent();
});
app.Run();
List<string> Validate(PokemonInput input)
{
var errors = new List<string>();
if (string.IsNullOrWhiteSpace(input.Name)) errors.Add("Имя не может быть пустым.");
if (string.IsNullOrWhiteSpace(input.Type)) errors.Add("Тип не может быть пустым.");
if (input.Level <= 0) errors.Add("Уровень должен быть больше 0.");
return errors;
}
public record Pokemon(int Id, string Name, string Type, int Level);
public record PokemonInput(string Name, string Type, int Level);
@@ -5,7 +5,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5116",
"applicationUrl": "http://localhost:5211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
@@ -14,7 +14,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "https://localhost:7103;http://localhost:5116",
"applicationUrl": "https://localhost:7050;http://localhost:5211",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
+21
View File
@@ -0,0 +1,21 @@
info:
name: "1 request "
type: http
seq: 1
http:
method: GET
url: https://pokeapi.co/api/v2/pokemon/pikachu
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
docs: |-
1 запрос:
Вывод покемона по имени
+23
View File
@@ -0,0 +1,23 @@
info:
name: 2 request
type: http
seq: 2
http:
method: GET
url: https://pokeapi.co/api/v2/pokemon/25
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
docs: |-
2 запрос:
Вывод покемона по id
<br/>
+28
View File
@@ -0,0 +1,28 @@
info:
name: 3 request
type: http
seq: 3
http:
method: GET
url: https://pokeapi.co/api/v2/pokemon?limit=5&offset=0
params:
- name: limit
value: "5"
type: query
- name: offset
value: "0"
type: query
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
docs: |-
3 запрос:
Вывод списка покемонов
+21
View File
@@ -0,0 +1,21 @@
info:
name: 4 request
type: http
seq: 4
http:
method: GET
url: https://pokeapi.co/api/v2/type/electric
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
docs: |-
4 запрос:
Вывод информации о типе
+29
View File
@@ -0,0 +1,29 @@
info:
name: 5 request
type: http
seq: 5
http:
method: POST
url: https://jsonplaceholder.typicode.com/posts
body:
type: json
data: |-
{
"title": "Мой первый покемон",
"body": "Поймал Пикачу!",
"userId": 1
}
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
docs: |-
5 запрос:
Создания ресурсов
+23
View File
@@ -0,0 +1,23 @@
info:
name: 6 request
type: http
seq: 6
http:
method: GET
url: https://pokeapi.co/api/v2/pokemon/unknown-pokemon-xyz
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
docs: |-
запрос 6:
Вывод ошибки
<br/>
@@ -1,7 +1,7 @@
opencollection: 1.0.0
info:
name: Lab1 — PokeAPI
name: lab-01 - PokeAPI
bundled: false
extensions:
bruno:
@@ -0,0 +1,28 @@
info:
name: request bonus
type: http
seq: 7
http:
method: GET
url: https://pokeapi.co/api/v2/pokemon?limit=3&offset=10
params:
- name: limit
value: "3"
type: query
- name: offset
value: "10"
type: query
auth: inherit
settings:
encodeUrl: true
timeout: 0
followRedirects: true
maxRedirects: 5
forwardAuthorizationHeader: false
docs: |-
запрос 7:
Вывод информация о покемонах 3 со смещением 10
+185
View File
@@ -0,0 +1,185 @@
{
"openapi": "3.1.1",
"info": {
"title": "PokedexApi | v1",
"version": "1.0.0"
},
"servers": [
{
"url": "http://localhost:5211/"
}
],
"paths": {
"/hello": {
"get": {
"tags": [
"PokedexApi"
],
"responses": {
"200": {
"description": "OK",
"content": {
"text/plain": {
"schema": {
"type": "string"
}
}
}
}
}
}
},
"/pokemons": {
"get": {
"tags": [
"PokedexApi"
],
"responses": {
"200": {
"description": "OK"
}
}
},
"post": {
"tags": [
"PokedexApi"
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PokemonInput"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
}
},
"/pokemons/{id}": {
"get": {
"tags": [
"PokedexApi"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"pattern": "^-?(?:0|[1-9]\\d*)$",
"type": [
"integer",
"string"
],
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
},
"put": {
"tags": [
"PokedexApi"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"pattern": "^-?(?:0|[1-9]\\d*)$",
"type": [
"integer",
"string"
],
"format": "int32"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/PokemonInput"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "OK"
}
}
},
"delete": {
"tags": [
"PokedexApi"
],
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"pattern": "^-?(?:0|[1-9]\\d*)$",
"type": [
"integer",
"string"
],
"format": "int32"
}
}
],
"responses": {
"200": {
"description": "OK"
}
}
}
}
},
"components": {
"schemas": {
"PokemonInput": {
"required": [
"name",
"type",
"level"
],
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"type": "string"
},
"level": {
"pattern": "^-?(?:0|[1-9]\\d*)$",
"type": [
"integer",
"string"
],
"format": "int32"
}
}
}
}
},
"tags": [
{
"name": "PokedexApi"
}
]
}